获取bing首页图片
import urllib,re,sys,os def get_bing_backphoto(): if (os.path.exists('photos')== False): os.mkdir('photos') for i in range(0,10): 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!' 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 imgurl="http://www.bing.com"+imgurl urllib.urlretrieve(imgurl, savepath) print name + ' save success!' get_bing_backphoto()
还是放文章里吧,毕竟不是原创
浙公网安备 33010602011771号