小编Dav*_*vid的帖子

'NoneType'对象没有属性'group'

有人可以帮我这个代码吗?我正在尝试制作一个可以播放视频的python脚本,我发现这个文件可以下载Youtube视频.我不完全确定发生了什么,我无法弄清楚这个错误.

错误:

AttributeError: 'NoneType' object has no attribute 'group'
Run Code Online (Sandbox Code Playgroud)

追溯:

Traceback (most recent call last):
  File "youtube.py", line 67, in <module>
    videoUrl = getVideoUrl(content)
  File "youtube.py", line 11, in getVideoUrl
    grps = fmtre.group(0).split('&amp;')
Run Code Online (Sandbox Code Playgroud)

代码段:

(第66-71行)

content = resp.read()
videoUrl = getVideoUrl(content)

if videoUrl is not None:
    print('Video URL cannot be found')
    exit(1)
Run Code Online (Sandbox Code Playgroud)

(第9-17行)

def getVideoUrl(content):
    fmtre = re.search('(?<=fmt_url_map=).*', content)
    grps = fmtre.group(0).split('&amp;')
    vurls = urllib2.unquote(grps[0])
    videoUrl = None
    for vurl in vurls.split('|'):
        if vurl.find('itag=5') > 0:
            return vurl
    return None
Run Code Online (Sandbox Code Playgroud)

python youtube download

17
推荐指数
2
解决办法
7万
查看次数

标签 统计

download ×1

python ×1

youtube ×1