几秋
2018-04-23 20:11
import re import urllib req = urllib.request.urlopen('https://www.imooc.com/course/list') buf = req.read().decode("utf-8") # listurl = re.findall(r'src=.+\.jpg', buf) listurl = re.findall(r'//img.+?\.jpg', buf) for index,app_id in enumerate(listurl): listurl[index] = str(app_id).replace('//', 'http://') print(index, listurl[index]) print(listurl) i = 0 for url in listurl: f = open(str(i) + ".jpg", "wb+") req = urllib.request.urlopen(url) buf = req.read() f.write(buf) i += 1
用urllib2也可以
import urllib2
page = urllib2.urlopen(url)
import urllib.request
python正则表达式
80575 学习 · 174 问题
相似问题