问答详情
源自:4-2 python正则表达式练习

为什么我下载图片看不清楚 或者是破图

# -*- coding: UTF-8 -*-
import urllib2
import re
import time
req = urllib2.urlopen('http://www.imooc.com/course/list?c=python')
buf =req.read()
listurl = re.findall(r'http://img.+.jpg',buf)
print listurl

i = 0
for url in listurl:
   file = open('D:/python/'+str(i)+'.jpg','w')
   req = urllib2.urlopen(url)
   buf = req.read()
   file.write(buf)
   i += 1
   time.sleep(1)

提问者:风月v 2016-07-31 15:20

个回答

  • 慕粉3772989
    2016-08-07 23:00:30

    file = open('D:/python/'+str(i)+'.jpg','wb')

    试一试二进制打开方式