Python批量唯美類圖片
阿新 • • 發佈:2019-05-10
lose __name__ itl -a htm 4.0 __main__ ron quest
效果圖:
實現代碼:
# -*- coding: UTF-8 -*- import requests import re urls = [‘http://www.ik123.com/q/tuku/weimei/list_11_{}.html‘.format(str(i)) for i in range(1, 201)] headers={ ‘Referer‘: ‘http://www.ik123.com/q/tuku/weimei/list_11_1.html‘, ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36‘ } def list_info(url): res = requests.get(url) res.encoding = ‘GB2312‘ srcs = re.findall("<img style=‘width: 190px; height: 130px‘ src=‘(.*?)‘ alt=‘.*?‘/>", res.text, re.S) titles = re.findall("<img style=‘width: 190px; height: 130px‘ src=‘.*?‘ alt=‘[<b>]?(.*?)[</b>]?‘/>", res.text, re.S) for src, title in zip(srcs, titles): try: info = { ‘src‘: src, ‘title‘: title } print(info) pic=requests.get(info[‘src‘],headers=headers) f=open(‘pic\\‘+str(info[‘title‘])+‘.jpg‘, ‘wb‘) f.write(pic.content) f.close() except IndexError: pass if __name__ == ‘__main__‘: for url in urls: list_info(url)
Python批量唯美類圖片