python之爬蟲-必應壁紙


python之爬蟲-必應壁紙

import re
import requests
"""
@author RansySun
@create 2019-07-19-20:26
"""

"""
https://bing.ioliu.cn/?p=1"
https://bing.ioliu.cn/?p=2"
https://bing.ioliu.cn/?p=3"

"""
count  = 1
for i in range(50):
    url = f"https://bing.ioliu.cn/?p={i}"
    reponse = requests.get(url)
    data = reponse.text
    # 獲取必應壁紙圖片的鏈接
    result_list = re.findall('src="(.*?)"', data)
    g = 0
    for result in result_list: 
        # 處理其他鏈接
        if g < 4:
            g += 1
            continue
        # 判斷是否是圖片的鏈接
        if result.startswith("https"):            
            # 請求圖片地址           
            img_response = requests.get(result)
            img_data = img_response.content
            # 獲取圖片名
            img_name = result.split("/")[-1].split("_")[0]+".jpg"
            img_star_name = str(count) + "_" + img_name
		   # 寫入圖片
            with open(img_star_name, "wb") as fw:
                fw.write(img_data)
                print("爬取成功:", img_star_name)
                fw.flush()
            count += 1
            print(result)

結果:
爬蟲必應壁紙

必用壁紙


免責聲明!

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



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