Skip to content

Instantly share code, notes, and snippets.

@IanSmith123
Created August 17, 2017 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanSmith123/b496cad832b7755dbee8e95acb3c1b2d to your computer and use it in GitHub Desktop.
Save IanSmith123/b496cad832b7755dbee8e95acb3c1b2d to your computer and use it in GitHub Desktop.
download bing wall paper for recent 7 days
import requests
sample_api_url = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"
# notice: add a num after "idx=", this is the count of day before today
api_url = "http://www.bing.com/HPImageArchive.aspx?format=js&n=1&idx="
def get_pic_url(num):
r = requests.get(api_url+repr(num))
con = r.json()
pic_url = con['images'][0]['url']
pic_intro = con['images'][0]['copyright'].split()[0]
print('\n')
print(pic_url)
print(pic_intro)
return 'http://www.bing.com'+pic_url, pic_intro
def download_pic(info):
pic_url = info[0]
pic_intro = info[1]
print('download', pic_intro)
r = requests.get(pic_url)
with open('pic/' + pic_intro + '.' + pic_url.split('.')[-1], 'wb') as f:
f.write(r.content)
f.close()
def wapper(num):
download_pic(get_pic_url(num))
for i in range(8):
wapper(i)
@IanSmith123
Copy link
Author

{  
   "images":[  
      {  
         "startdate":"20170816",
         "fullstartdate":"201708161600",
         "enddate":"20170817",
         "url":"/az/hprichbg/rb/GoldenHorn_ZH-CN14570526834_1920x1080.jpg",
         "urlbase":"/az/hprichbg/rb/GoldenHorn_ZH-CN14570526834",
         "copyright":"布拉奇岛上的尖角海滩,克罗地亚 (© mbbirdy/E+/Getty Images)",
         "copyrightlink":"http://www.bing.com/search?q=%E5%B0%96%E8%A7%92%E6%B5%B7%E6%BB%A9&form=hpcapt&mkt=zh-cn",
         "quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20170816_GoldenHorn%22&FORM=HPQUIZ",
         "wp":true,
         "hsh":"c5c0178c86839d713cd8581d1b44a12e",
         "drk":1,
         "top":1,
         "bot":1,
         "hs":[  

         ]
      }
   ],
   "tooltips":{  
      "loading":"正在加载...",
      "previous":"上一个图像",
      "next":"下一个图像",
      "walle":"此图片不能下载用作壁纸。",
      "walls":"下载今日美图。仅限用作桌面壁纸。"
   }
}

@IanSmith123
Copy link
Author

This is what the api return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment