python:偷取bing首页面图片作为桌面背景
2013-03-06 14:43
465 查看
import os import sys import random import urllib import win32gui import win32con import Image class StealBing: def __init__(self): self.content = urllib.urlopen('http://cin.bing.com/').read() self.bgImageUrl = '' self.localFileName = '' self.localBMPFileName = '' def parserImageUrl(self): temp = self.content[self.content.index('g_img={url:') + len('g_img={url:') + 1 : len(self.content)] temp = temp[0 : temp.index(',id:') - 1] print temp print temp self.bgImageUrl = temp def createLocalFileName(self): randomStr = ''.join(random.sample(['a','b','c','d','e','f','g','h','i','j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], 6)).replace('', '') self.localFileName = 'd:\\bg_pictures\\' + randomStr + '.jpg' self.localBMPFileName = 'd:\\bg_pictures\\' + randomStr + '.bmp' def downloadImage(self): if self.bgImageUrl == '': self.parserImageUrl() if self.localFileName == '': self.createLocalFileName() data = urllib.urlretrieve(self.bgImageUrl, self.localFileName) def updateBGImage(self): img = Image.open(self.localFileName) img.save(self.localBMPFileName) os.remove(self.localFileName) win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, self.localBMPFileName, 0) stealing = StealBing() stealing.downloadImage() stealing.updateBGImage()
相关文章推荐
- python3 抓取必应bing首页图片作为桌面背景
- 自定义制作 自动定时更换图片的桌面背景 html页面
- 自定义制作 自动定时更换图片的桌面背景 html页面
- 网页页面[置顶] 让图片作为整个网页背景
- 使用Python脚本将Bing的每日图片作为桌面的教程
- React-Native 如何将图片作为页面的背景以及控件的嵌套实现启动应用
- Python爬虫之提取Bing搜索的背景图片并设置为Windows的电脑桌面
- React-Native 如何将图片作为页面的背景以及控件的嵌套实现启动应用
- 图片作为背景,登陆页面相对定位
- 使用Python脚本将Bing的每日图片作为桌面的教程
- React-Native 背景图片全屏显示及登录页面
- python爬虫:从页面下载图片以及编译错误解决。
- 聊天页面由于键盘弹出来,导致自定义的标题栏不见和背景图片都变形了
- java编程过程中中如何在JFrame面板添加图片作为背景
- python scrapy 爬取bing的背景图片
- python之利用PIL库实现页面的图片验证码及缩略图 推荐
- 使用9Patch图片作为按钮背景
- Firefox BUG:页面太大的时候background-image背景图片渲染出错
- app引导页(背景图片切换加各个页面动画效果)
- 安卓视频播放API--VideoView如何加载项目视频资源,如何全屏播放,如何作为欢迎页面的背景显示?