我想用 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/