獲取圖片做桌面壁紙

#encoding:utf-8
import urllib,re,time

def getpic():
    mf = urllib.urlopen('http://cn.bing.com')
    content = mf.read()
    
    picurls = re.findall('url:\'(.*?)\',id',content)
    today=time.strftime('%Y%m%d',time.localtime(time.time()))
    descs=re.findall('今日圖片故事</h3><a.*?>(.*?)<'.decode('utf-8'), content.decode('utf-8'))
    
    desc=''
    if descs:
        desc=descs[0]
    
    for pic in picurls:
        p=urllib.urlopen(pic).read()
        open(today+'_'+desc+'.jpg', 'wb').write(p)
    

getpic()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章