Chinaunix
标题:
错误:<type 'exceptions.IOError'> ,可以帮我看看吗?
[打印本页]
作者:
皮影09
时间:
2015-04-22 21:44
标题:
错误:<type 'exceptions.IOError'> ,可以帮我看看吗?
import re
import urllib
import sys
from cgitb import html
def get(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getima(html):
res = r'src="//(.*\.png)"'
# <img width="890" height="440" src="//img.alicdn.com/tps/i4/TB16yXvHFXXXXXkXVXXblszJFXX-890-440.png" alt="" />
ress = re.compile(res)
list_ima = ress.findall(html)
print list_ima
i = 0
for x in list_ima:
print x
print'------------------------------------------'
try:
urllib.urlretrieve(x,'%s.jpg' % i)
except:
print "Unexpected error:", sys.exc_info()[0]
i+=1
print '%s has been downloaded' % i
html = get("mm.taobao.com")
getima(html)
复制代码
错误信息:Unexpected error: <type 'exceptions.IOError'>
请问我应该怎么改正?
作者:
haooooaaa
时间:
2015-04-23 09:36
本帖最后由 haooooaaa 于 2015-04-23 09:36 编辑
这样就好了, 测试了一下
urllib.urlretrieve('H__P://%s' % x,'%s.jpg' % i)
上面的 H__P 换 http
还有 mm.taobao.com 前面也加上 http
作者:
皮影09
时间:
2015-04-23 20:47
回复
2#
haooooaaa
还是不行啊。。还是提示一样的错误。。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2