皮影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()
      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

还是不行啊。。还是提示一样的错误。。


   
页: [1]
查看完整版本: 错误:<type 'exceptions.IOError'> ,可以帮我看看吗?