zoukankan      html  css  js  c++  java
  • 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)
    
    

    结果:
    爬虫必应壁纸

    必用壁纸

    在当下的阶段,必将由程序员来主导,甚至比以往更甚。
  • 相关阅读:
    重回大一
    20071027我以为我很大度
    凌晨三点
    山洞爱情
    JQuery上传插件Uploadify使用详解
    jquery ui layout
    win2003下direct的问题
    Aptana一些快键用法
    IE、Firefox、Chrome 的JS代码兼容注意事项
    2011学习计划
  • 原文地址:https://www.cnblogs.com/randysun/p/11216218.html
Copyright © 2011-2022 走看看