import re import time import urllib.request url = 'http://www.douban.com' req = urllib.request.urlopen(url) data = req.read().decode('utf-8') match = re.compile("data-origin=\"(.+?\.jpg)") f = open('D:\\1.txt', 'w+') for sj in match.findall(data): try: f.write(sj) except: print("fail") f.write('\n') f.close() f1 = open('D:\\1.txt', 'r+') x = 0 for lj in f1.readlines(): img = urllib.request.urlretrieve(lj, 'D:/2/%s.jpg' % x) x += 1 f1.close()
Python3 网络爬虫之抓取图片
最新推荐文章于 2024-06-17 11:32:50 发布