python抓取Bing每天的桌面,并设置为自己的桌面,pythonbing,Python语言: 偷取
python抓取Bing每天的桌面,并设置为自己的桌面,pythonbing,Python语言: 偷取
Python语言: 偷取Bing每天的桌面,并设置为自己的桌面
# -*- coding: cp936 -*-'''Created on 2009-8-17@author: lign偷取Bing的背景图片,并设置为自己的桌面背景,随后加入预览和定时偷取'''import osimport sysimport randomimport urllibimport win32guiimport win32conimport Imageclass StealBing: def __init__(self): self.content = urllib.urlopen('http://cn.bing.com/').read() self.bgImageUrl = '' self.localFileName = '' self.localBMPFileName = '' def parserImageURL(self): tempStr = self.content[self.content.index('g_img={url:')+12:len(self.content)] tempStr = tempStr[0:tempStr.index(',id:')-1] tempStr = tempStr.replace('\\', '') self.bgImageUrl = 'http://cn.bing.com'+tempStr #仅用于生成本地文件名 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 = 'c:/temp/' + randomStr + '.jpg' self.localBMPFileName = 'c:/temp/' + randomStr + '.bmp' def downloadImage(self): if self.bgImageUrl == '': self.parserImageURL() if self.localFileName == '': self.createLocalFileName() data = urllib.urlretrieve(self.bgImageUrl, self.localFileName) def updataBGImage(self): img = Image.open(self.localFileName) img.save(self.localBMPFileName) os.remove(self.localFileName) win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, self.localBMPFileName , 0)if __name__ == '__main__': stealBing = StealBing() stealBing.downloadImage() stealBing.updataBGImage()
相关内容
- python random从集合中随机选择元素,pythonrandom,使用pyth
- python安装mysql包命令,pythonmysql命令,python使用easy
- python在win7(32位和64)下安装PIL,win7pil,PIL是python下的
- 在windows 7下安装python+xapian,pythonxapian,xapian的官方网站
- Python 最近最少使用算法,Python使用算法,# lrucache.p
- Python生成目录树,python生成目录,# encoding:
- python在运行时给class添加方法,pythonclass,下面的代码演
- 偷取Bing每天的桌面,并设置为自己的桌面,bing,Python语
- python sqlite3的常规使用,pythonsqlite3常规,#Filename: D
- python读取目录下文件并生成日志,,import os f
评论关闭