python 爬取图片路径规则并保存本地

爬取图片路径规则并保存本地

import re
import requests

temp = 'http://wufazhuce.com/one/'
count = 1
for i in range(14, 1580):
    url = temp + str(i)
    page = requests.get(url).text
    reg = re.compile('<img src="(http://.*?)" alt="" />')
    img_url = re.findall(reg, page)
    if img_url != []:
        with open('./{}.jpg'.format(count), 'wb') as file:
            try:
                img_data = requests.get(img_url[0]).content
                file.write(img_data)
                count += 1
            except:
                pass
print('OK!')
posted @ 2020-11-18 11:44  莫贞俊晗  阅读(665)  评论(0编辑  收藏  举报