最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python爬取必应壁纸的代码实例
时间:2020-02-24 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Python爬取必应壁纸的代码实例,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
代码如下:
import re import os import requests from time import sleep headers = { "User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) " "Gecko/20100101 Firefox/64.0") } def get_index(resolution, index=1): url = f"https://bing.ioliu.cn/ranking?p={index}" res = requests.get(url, headers=headers) urls = re.findall('pic=(.*?)\.jpg', res.text) _old_resolution = urls[1].split("_")[-1] return {url.split("/")[-1].replace(_old_resolution, resolution): url.replace(_old_resolution, resolution) + ".jpg" for url in urls} def download_pic(pics): if os.path.exists('F:\必应壁纸'): pass else: os.mkdir('F:\必应壁纸') print('目录创建成功') try: for pic_name, pic_url in pics.items(): res = requests.get(pic_url, headers=headers) with open(f"F:\必应壁纸\{pic_name}.jpg", mode="wb") as f: f.write(res.content) print(f"{pic_name} 下载完成") except Exception as e: print("下载出错", e) def input_index(): print("必应壁纸下载工具, 本工具未经资源站授权.") print("仅做学习和交流之用, 随时有可能停止维护.") print("目前资源站收容页数为87,当前仅提供1920x1080分辨率下载") while True: sleep(0.1) index = input("请输入要下载的页数(Max=87):") try: if index == "Q": exit() index = 87 if int(index) > 87 else int(index) return index except ValueError: print("请输入数字, 或输入Q退出!") def main(): index = input_index() i = 1 while i <= index: print(f"当前第{i}页,共需要下载{index}页") pics = get_index("1920x1080", i) download_pic(pics) i += 1 print("下载完成,将在3秒后关闭...") sleep(1) print("2") sleep(1) print("1") sleep(1) print("0") if __name__ == '__main__': main()
-
上一个: php7 图形用户界面GUI如何开发
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27