Chinaunix

标题: 错误:<type 'exceptions.IOError'> ,可以帮我看看吗? [打印本页]

作者: 皮影09    时间: 2015-04-22 21:44
标题: 错误:<type 'exceptions.IOError'> ,可以帮我看看吗?
  1. import re
  2. import urllib
  3. import sys
  4. from cgitb import html
  5. def get(url):
  6.     page = urllib.urlopen(url)
  7.     html = page.read()
  8.     return html

  9. def getima(html):
  10.     res = r'src="//(.*\.png)"'
  11.     # <img width="890" height="440" src="//img.alicdn.com/tps/i4/TB16yXvHFXXXXXkXVXXblszJFXX-890-440.png" alt="" />

  12.     ress = re.compile(res)
  13.     list_ima = ress.findall(html)
  14.     print list_ima
  15.     i = 0
  16.     for x in list_ima:
  17.         print x
  18.         print'------------------------------------------'
  19.         try:
  20.             urllib.urlretrieve(x,'%s.jpg' % i)
  21.         except:
  22.             print "Unexpected error:", sys.exc_info()[0]
  23.         i+=1
  24.         print '%s has been downloaded' % i

  25. html = get("mm.taobao.com")
  26. 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