在网上看到的不错的Python抓取脚本,而且Bing的背景图片确实很不错,不仅如此,原作者写的脚本那也是短小精悍,值得收藏:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# python抓取bing主页所有背景图片
import urllib, re, sys, os
def get_bing_backphoto():
if (os.path.exists('photos')== False):
os.mkdir('photos')
for i in range(0, 100):
url = 'http://cn.bing.com/HPImageArchive.aspx?format=js&idx=' + str(i) + '&n=1&nc=1361089515117&FORM=HYLH1'
html = urllib.urlopen(url).read()
if html == 'null':
print 'open & read bing error @ ' + str(i)
sys.exit(-1)
reg = re.compile('"url":"(.*?)","urlbase"', re.S)
text = re.findall(reg, html)
#http://s.cn.bing.net/az/hprichbg/rb/LongJi_ZH-CN8658435963_1366x768.jpg
for imgurl in text:
right = imgurl.rindex('/')
name = imgurl.replace(imgurl[:right + 1], '')
savepath = 'photos/' + name
urllib.urlretrieve(imgurl, savepath)
print name + ' save success!'
get_bing_backphoto()
可以去原作者的blog里面看他的分析过程,也是个学习的过程。
原文链接:
http://yxmhero1989.blog.163.com/blog/static/112157956201311743439712/
《“用python脚本抓取bing主页背景图片”》 有 1 条评论
Bing每日壁纸
http://www.bing.com/HPImageArchive.aspx?format=rss&idx=0&n=1&mkt=en-US
Nasa每日图片
https://www.nasa.gov/rss/dyn/image_of_the_day.rss
国家地理中文网
http://www.nationalgeographic.com.cn/index.php?m=content&c=feed
维基百科 – 今日图片
https://zh.wikipedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=atom