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)

结果:
爬虫必应壁纸

必用壁纸

转载于:https://www.cnblogs.com/randysun/p/11216218.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值