import requests import time import re
timestamp = str(int(time.time() * 1000))
url = 'https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&nc=' + timestamp + '&pid=hp'
headers = { 'User-Agent': ' '.join(['Mozilla/5.0 (Windows NT 10.0; Win64; x64; ServiceUI 14)', 'AppleWebKit/537.36 (KHTML, like Gecko)', 'Chrome/70.0.3538.102', 'Safari/537.36', 'Edge/18.18363']) }
r = requests.get(url=url, headers=headers)
result = r.json()
image_url = result['images'][0]['url']
name = re.search( r'id=(.*\.jpg)&rf', image_url)
image_url = 'https://cn.bing.com' + image_url
save_image_file = '/home/samba/bing/' + name[1]
r = requests.get(url=image_url, headers=headers)
with open(save_image_file, 'wb') as f: f.write(r.content)
|