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

NoneType对象没有属性'span‘
EN

Stack Overflow用户
提问于 2022-02-03 18:29:46
回答 1查看 1.5K关注 0票数 1

我试着按照pytube示例从YouTube下载视频:

代码语言:javascript
运行
复制
from pytube import YouTube
video = YouTube('https://www.youtube.com/watch?v=BATOxzbVNno')
video.streams.all()

并立即得到这个错误:

代码语言:javascript
运行
复制
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-2556eb2eb903> in <module>()
      1 from pytube import YouTube
      2 video = YouTube('https://www.youtube.com/watch?v=BATOxzbVNno')
----> 3 video.streams.all()

5 frames
/usr/local/lib/python3.7/dist-packages/pytube/cipher.py in get_throttling_function_code(js)
    301     # Extract the code within curly braces for the function itself, and merge any split lines
    302     code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n')
--> 303     joined_lines = "".join(code_lines_list)
    304 
    305     # Prepend function definition (e.g. `Dea=function(a)`)

AttributeError: 'NoneType' object has no attribute 'span'

请帮帮我。昨天还挺好的!非常感谢!

EN

Stack Overflow用户

回答已采纳

发布于 2022-02-10 09:33:45

只是我自己遇到了那个错误,似乎它经常发生,不管它得到了临时的修复。

在github上找到一个修复程序:NoneType对象没有属性'span‘

只需将函数get_throttling_function_name替换为:

代码语言:javascript
运行
复制
def get_throttling_function_name(js: str) -> str:
"""Extract the name of the function that computes the throttling parameter.

:param str js:
    The contents of the base.js asset file.
:rtype: str
:returns:
    The name of the function used to compute the throttling parameter.
"""
function_patterns = [
    # https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
    # a.C&&(b=a.get("n"))&&(b=Dea(b),a.set("n",b))}};
    # In above case, `Dea` is the relevant function name
    r'a\.[A-Z]&&\(b=a\.get\("n"\)\)&&\(b=([^(]+)\(b\)',
]
logger.debug('Finding throttling function name')
for pattern in function_patterns:
    regex = re.compile(pattern)
    function_match = regex.search(js)
    if function_match:
        logger.debug("finished regex search, matched: %s", pattern)
        function_name = function_match.group(1)
        is_Array = True if '[' or ']' in function_name else False
        if is_Array:
            index = int(re.findall(r'\d+', function_name)[0])
            name = function_name.split('[')[0]
            pattern = r"var %s=\[(.*?)\];" % name
            regex = re.compile(pattern)
            return regex.search(js).group(1).split(',')[index]
        else:
            return function_name

raise RegexMatchError(
    caller="get_throttling_function_name", pattern="multiple"
)
票数 4
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70976489

复制
相关文章

相似问题

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