首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoneType: AttributeError:'span‘对象没有’span‘属性

NoneType: AttributeError:'span‘对象没有’span‘属性
EN

Stack Overflow用户
提问于 2021-11-22 02:24:59
回答 2查看 10.4K关注 0票数 14

我刚刚下载了pytube (Version11.0.1),并从here的以下代码片段开始

代码语言:javascript
复制
from pytube import YouTube
YouTube('https://youtu.be/9bZkp7q19f0').streams.first().download()

这就产生了这个错误:

代码语言:javascript
复制
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)中运行这段代码。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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。

票数 17
EN

Stack Overflow用户

发布于 2021-11-22 14:13:14

我也遇到了同样的问题,我像上面的答案一样修改了parser.py,只是在GitHub上派生了pytube lib,并更改了文件。

你可以这样安装pytube:

代码语言:javascript
复制
pip install git+https://github.com/baxterisme/pytube

而不是:

代码语言:javascript
复制
pip install pytube
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70060263

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档