有人可以帮我处理这段代码吗?我试图制作一个可以播放视频的python脚本,并且我发现这个文件是下载的Youtube视频。我不完全确定发生了什么,我无法弄清楚这个错误。'NoneType'对象没有属性'group'
错误:
AttributeError: 'NoneType' object has no attribute 'group'
回溯:
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('&')
代码片断:
(线66-71)
content = resp.read()
videoUrl = getVideoUrl(content)
if videoUrl is not None:
print('Video URL cannot be found')
exit(1)
(系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
@omouse你想看到我所有的代码?这个问题已经回答了 – David 2013-02-26 02:36:51
我很明显在努力学习,不需要这么关键 – David 2013-02-26 02:46:55