» 您尚未登录:请 登录 | 注册 | 标签 | 帮助 | 小黑屋 |


发新话题
打印

[其他] 中年入门程序员作品,Mac下自动下载Bing每日墙纸的Python script,16楼

复制内容到剪贴板
代码:
import httplib2
import os.path

h = httplib2.Http('cache')
headers = {'Content-type': 'application/x-www-form-urlencoded'}
url = 'http://www.bing.com/'
response, content = h.request(url, 'GET')

htmlContent = content.decode('utf-8')
imageUrl = htmlContent[htmlContent.find(';g_img'):]
imageUrl = imageUrl[imageUrl.find("'") + 1:]
imageUrl = imageUrl[:imageUrl.find("'")]
imageUrl = imageUrl.replace('1366x768', '1920x1080')

print(imageUrl)
response, content = h.request(imageUrl, 'GET')

imageFile = open(os.path.basename(imageUrl), 'wb')
imageFile.write(content)
imageFile.close()
看了下源代码 好像就一处有 不是'background-image'那里 直接提出来算了


本帖最近评分记录
  • eva3d 激骚 +5 感谢分享 2013-9-26 08:56

TOP

发新话题
     
官方公众号及微博