当尝试使用pytube API库访问Youtube视频的“标题”之类的数据时,我收到以下错误
正则表达式模式:正则表达式模式(yt.akamaized.net/)\s*||\s*.?\s_c\s*&&\s_d.set(^,+\s,\s*(?Pa-zA-Z0-9$+)()没有匹配项
这是我正在使用的代码,它提供了上面的错误。
import sys
import pytube
link = input('Enter url: ') # url is: https://www.youtube.com/watch?v=KSbj-cFtFPA
yt = pytube.YouTube(link)
print(yt.title)
sys.exit()
有人知道如何解决这个错误吗?我已经做了一些在线搜索,提供的答案不确定,当我尝试的时候也不起作用。
注意:我试图卸载并重新安装pytube,但这并没有解决问题。
发布于 2019-01-04 11:36:29
pytube中有一个bug,所以使用这个命令重新安装它。
pip install git+https://github.com/nficano/pytube.git
#####################################################
import sys
import pytube
link = input('Enter url: ') # url is: https://www.youtube.com/watch?v=KSbjcFtFPA
yt = pytube.YouTube(link)
print(yt.title)
**OUTPUT** Sanford and Son S02E02
sys.exit()
以下是有关此错误的一些附加信息:https://github.com/nficano/pytube/issues/333
这是对该问题的后续回答。我根据文档添加了一些错误处理,以告诉您发生了什么。
- Video 1 in the list will throw an extraction error. because the video has been removed from YouTube
- Video 2 in the list will throw an unavailable error. because the video does not exist on YouTube
- Video 3 in the list will display the correct title info, because the video exists on YouTube.
video_lists = ['https://www.youtube.com/watch?v=KSbjcFtFPA',
'https://www.youtube.com/watch?v=MEEJOZkmIxvU',
'https://www.youtube.com/watch?v=MEEJOZkmIxU'
]
for video in video_lists:
try:
yt = pytube.YouTube(video)
print (yt.title)
#################################################################
# This one should catch - pytube.exceptions.RegexMatchError:
# regex pattern ((?:v=|\/)([0-9A-Za-z_-]{11}).*) had zero matches
#################################################################
except pytube.exceptions.RegexMatchError:
print('The Regex pattern did not return any matches for the video: {}'.format(video))
except pytube.exceptions.ExtractError:
print ('An extraction error occurred for the video: {}'.format(video))
except pytube.exceptions.VideoUnavailable:
print('The following video is unavailable: {}'.format(video))
**OUTPUTS**
An extraction occurred for the video: https://www.youtube.com/watch?v=KSbjcFtFPA
The following video is unavailable: https://www.youtube.com/watch?v=MEEJOZkmIxvU
Love of my life & Bohemian Rhapsody - 1080 HD
特别说明
有问题的错误已链接到pytube的文件cipher.py。请检查此文件,以确保以下代码部分与您的代码部分匹配:
def get_initial_function_name(js):
"""Extract the name of the function responsible for computing the signature.
:param str js:
The contents of the base.js asset file.
"""
# c&&d.set("signature", EE(c));
pattern = r'\bc\s*&&\s*d\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P<sig>[a-zA-Z0-9$]+)\('
logger.debug('finding initial function name')
return regex_search(pattern, js, group=1)
发布于 2019-04-26 10:32:02
@ Victor S:尝试安装pytube和pytubetemp,确保两者都是9.4.0。不要更改导入,重新运行您的代码。
https://stackoverflow.com/questions/54028675
复制相似问题