python - Pytube Channel video_urls 不起作用

标签 python pytube youtube-channels

我想用 pytube Channel 抓取 youtube channel ,但我收到索引错误,因为我的 URL 为零。其他一切都运行良好,只是 video_urls 不起作用。

我的代码:

c = Channel("https://www.youtube.com/c/BuildEmpire")
print(f"This is a test number of video urls:  {len(c.video_urls)}")
for url in c.video_urls[:20]:
  video = YouTube(url)
  description2 = video.description
  try:
    videos_credits = slicer(description2,"Video Credits:")
    videos_credits = reversed_slicer(videos_credits,"Thumbnail:")
    urls = re.findall(r'(https?://[^\s]+)', videos_credits)
  except Exception:
    print("Sorry but I choose bad youtube video I will try it again")

我得到的错误是:

PS C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle> & "c:/Users/Lukas/Dokumenty/python_scripts/Billionare livestyle/env/youtube/Scripts/python.exe" "c:/Users/Lukas/Dokumenty/python_scripts/Billionare livestyle/bilionare_life.py"
[]
0
Traceback (most recent call last):
  File "C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\env\youtube\lib\site-packages\pytube\helpers.py", line 57, in __getitem__
    next_item = next(self.gen)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\bilionare_life.py", line 198, in <module>
    for url in c.video_urls[:20]:
  File "C:\Users\Lukas\Dokumenty\python_scripts\Billionare livestyle\env\youtube\lib\site-packages\pytube\helpers.py", line 60, in __getitem__
    raise IndexError
IndexError

最佳答案

您没有检索到任何视频的原因是,这只是 pytube 端的问题,因为 YouTube 最近修改了其用户界面(pytube 依赖于此) ),和this issue is currently being resolved .

但是,作为临时解决方法,安装 pytube 可以解决问题:

pip install git+https://github.com/pishiko/pytube.git@42a7d8322dd7749a9e950baf6860d115bbeaedfc

关于python - Pytube Channel video_urls 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74334535/

相关文章:

youtube - 从YouTube API中自动生成的 channel 中获取视频

python - 我在数据框中有两列,一列有列名,另一列没有列名,我如何在 python pandas 上命名它们?

python - .dilate()OpenCV的替代方法

Python 集与列表

python - 使用pytube下载管视频时如何添加tqdm以显示进度栏?

youtube - 如何获取youtube.com/user/xxx channel 网址

video - 在YouTube上上传了不适当的视频

python - 生成列表的所有可能组合, "itertools.combinations"遗漏了一些结果

python - 获取 KeyError : 'url' with PyTube

python - 如何自动重命名从 pytube 下载的文件?