python正则报错AttributeError:'NoneTyep'object....,,import urlli
python正则报错AttributeError:'NoneTyep'object....,,import urlli
import urllibimport redef cbk(a, b, c): per = 100.0 * a * b / c if per > 100: per = 100 print '%.2f%%' % per def getHtml(url):page = urllib.urlopen(url)html = page.read()page.close()return htmldef getVideo(html):reg = 'src="(.*?.mp4)" 'reg2='\d{2}-\w+\.mp4$'videore = re.compile(reg)videourl = videore.findall(html)for vurl in videourl:print vurla=re.search(reg2, vurl)res=a.group()urllib.urlretrieve(vurl, res,cbk)nu = [11,12,13]for num in nu:lc = getHtml(r"http://www.linuxcast.net/public/cast_show/%s"%(num))print getVideo(lc)
报错如下:
re.search(reg2, vurl)
这个搜索不到匹配的内容,就返回None,自然就不能调用group()方法咯。。
是正则出错了,只看了一部分地址,没想到以前的地址是没有规律性的,导致正则不能搜索的正确的文件名。
编橙之家文章,
相关内容
- 在MySQL中运行timedelta时报错有图,求原因,mysqltimedelt
- python将变量作为字典key存储怎么操作,python变量字典
- python (2006, 'MySQL server has gone away'),pythonmysql,max_allowed
- python余数计算出错求解,python余数求解,def calculat
- Python pandas dataframe如何对某列的空数据位置进行update?
- 请问Flask-Security自带模板登陆、注册怎么实现中文化,
- python导入名称为数字开始的包报错SyntaxError: invalid syn
- 想短时间内完成Python学习,达到开发中小项目的途径是什
- python3 django关联内联关系应该如何操作,python3django,环境
- Python requests爬取网页出现EncodingError错误,,requests.exc
评论关闭