有人可以帮我这个代码吗?我正在尝试制作一个可以播放视频的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('&')
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('&')
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)