我刚刚下载了pytube (Version11.0.1),并从here的以下代码片段开始
from pytube import YouTube
YouTube('https://youtu.be/9bZkp7q19f0').streams.first().download()这就产生了这个错误:
AttributeError Traceback (most recent call last)
<ipython-input-29-0bfa08b87614> in <module>
----> 1 YouTube('https://youtu.be/9bZkp7q19f0').streams.first().download()
~/anaconda3/lib/python3.8/site-packages/pytube/__main__.py in streams(self)
290 """
291 self.check_availability()
--> 292 return StreamQuery(self.fmt_streams)
293
294 @property
~/anaconda3/lib/python3.8/site-packages/pytube/__main__.py in fmt_streams(self)
175 # https://github.com/pytube/pytube/issues/1054
176 try:
--> 177 extract.apply_signature(stream_manifest, self.vid_info, self.js)
178 except exceptions.ExtractError:
179 # To force an update to the js file, we clear the cache and retry
~/anaconda3/lib/python3.8/site-packages/pytube/extract.py in apply_signature(stream_manifest, vid_info, js)
407
408 """
--> 409 cipher = Cipher(js=js)
410
411 for i, stream in enumerate(stream_manifest):
~/anaconda3/lib/python3.8/site-packages/pytube/cipher.py in __init__(self, js)
42
43 self.throttling_plan = get_throttling_plan(js)
---> 44 self.throttling_array = get_throttling_function_array(js)
45
46 self.calculated_n = None
~/anaconda3/lib/python3.8/site-packages/pytube/cipher.py in get_throttling_function_array(js)
321
322 array_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)
--> 323 str_array = throttling_array_split(array_raw)
324
325 converted_array = []
~/anaconda3/lib/python3.8/site-packages/pytube/parser.py in throttling_array_split(js_array)
156 # Handle functions separately. These can contain commas
157 match = func_regex.search(curr_substring)
--> 158 match_start, match_end = match.span()
159
160 function_text = find_object_from_startpoint(curr_substring, match.span()[1])
AttributeError: 'NoneType' object has no attribute 'span'我想知道为什么?有谁可以帮我?我在一个使用Python3.8.8的ipython控制台(IPython版本7.22.0)中运行这段代码。
发布于 2021-11-22 07:03:23
发现了这个问题,pytube v11.0.1。现在对我来说有点晚了,但是如果明天没有人提交修复,我会检查一下。
在C:\Python38\lib\site-packages\pytube\parser.py中
更改此行:
152: func_regex = re.compile(r"function\([^)]+\)")
要这样做:
152: func_regex = re.compile(r"function\([^)]?\)")
问题是regex需要一个带参数的函数,但我猜youtube添加了一些包含非参数化函数的src。
发布于 2021-11-22 14:13:14
我也遇到了同样的问题,我像上面的答案一样修改了parser.py,只是在GitHub上派生了pytube lib,并更改了文件。
你可以这样安装pytube:
pip install git+https://github.com/baxterisme/pytube而不是:
pip install pytubehttps://stackoverflow.com/questions/70060263
复制相似问题