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

为什么req = urllib2.urlopen(url)会报错啊?而且只生成了一个无效图片

http://img.mukewang.com/5a75271e000163a112260640.jpg

http://img1.mukewang.com/5a75271f00018e5013710538.jpg

http://img1.mukewang.com/5a75271f0001162a13760496.jpg

我的正则表达式应该没有错

http://img4.mukewang.com/5a7527780001e39f16610915.jpg

import urllib2

import re 

req = urllib2.urlopen('https://www.imooc.com/course/list')

buf = req.read()

listurl = re.findall(r'src.*\.jpg',buf)

listurl = re.sub(r'src="','http:',str(listurl))

i = 0

for url in listurl:

    f = open('C:\\Users\\lenovo\\Desktop\\a\\'+str(i)+'.jpg','wb+')

    req = urllib2.urlopen(url)

    buf = req.read()

    f.write(buf)

    i = i + 1

print listurl


提问者:qq_夏威夷的晴空_0 2018-02-03 11:08

个回答