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!')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM