'''
抓取指定数量的bing.com的背景图片 。从当前日期开始 向前 n个日期的图图片

注意 #!后的解析器 路径以具体的 python3 路径
for i in range(10) 为抓取的个数

'''

1 #! /home/kele/anaconda3/bin/python
2 import requests
3 from pathlib import Path
4
5 def save_pic(path):
6 for i in range(10):
7 url="http://bingw.jasonzeng.dev?resolution=UHD&index={}".format(i)
8 with requests.get(url) as r:
9 with open(path/f"{i}.jpg","wb") as w:
10 w.write(r.content)
11
12 if name=="main":
13 saved_path=Path("bingdownload/bing_pic")
14 saved_path.mkdir(parents= True,exist_ok=True)
15 save_pic(saved_path)

posted on 2022-08-26 18:44  keleman  阅读(20)  评论(0编辑  收藏  举报