#-*- coding:utf-8 -*-
#Boa:Frame:Frame2
#保存并更换左桌面背景
import urllib
import sys, os, time, win32gui
url = r"http://www.baidu.com/img.jpg" #想要下载的图片
path = r"C:/Windows/Web/Wallpaper/img.jpg" #存放的路径
data = urllib.urlretrieve(url,path)
finalfile = []
file_type = ['jpg'] #'jpg', 'gif', 'jpeg', 'dib', 'png'
length = 0
pos = 0
dire = "C:/Windows/Web/Wallpaper/" #读取文件
if not os.path.exists(dire):
print "Not find dirction, please affirm your input!"
sys.exit("stop1")
list = os.listdir(dire)
for filename in list:
if len(filename.split('.')) == 2:
if filename.split('.') [1] in file_type:
finalfile.append(filename)
if finalfile.__eq__([]):
sys.exit("stop2")
SPI_SETDESKWALLPAPER = 0x14
length = len(finalfile)
win32gui.SystemParametersInfo(SPI_SETDESKWALLPAPER, dire+'/'+finalfile[pos] , 0)
#保存网页。。。。。。。。。。。。。。。
import urllib
import urllib2
import cookielib
cj=cookielib.LWPCookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
req=urllib2.Request('http://www.baidu.com')#下载网页的地址
operate = opener.open(req)
msg = operate.read()
file_object = open('D://baidu.html','w') #存放网页的路径
file_object.write(msg)
file_object.close()
做成exe运行:
具体参考http://blog.youkuaiyun.com/suiyunonghen/article/details/4033076
本文介绍了一种使用Python自动更换Windows桌面背景的方法,并演示了如何保存网页为本地HTML文件的过程。
1826

被折叠的 条评论
为什么被折叠?



