# -*- coding: utf-8 -*-""" http://www.gamersky.com/news/201309/297991.shtml """import urllib2 import urllib import re import string""" @param url:壁纸首页 @param begin:壁纸起始页 @param end:壁纸终止页 """ def GetPicture(url,begin,end):items = []for i in range(begin,end):if i == 1:myUrl = urlelse:myUrl = urltmps = '_' + str(i) + '.shtml'myUrl = string.replace(myUrl, '.shtml' , tmps)print myUrlmyResponse = urllib2.urlopen(myUrl)myPage = myResponse.read()myResponse.close()unicodePage = myPage.decode("utf-8")myItems = re.findall('<a target="_blank" href=".*?\?(.*?\.jpg)">',unicodePage,re.S)for item in myItems:items.append(item)return itemsdef Download_Pictures(items):for i in range(0,len(items)):sName = string.zfill(i,5) + '.jpg'f = file(sName, 'wb')data = urllib2.urlopen(items[i]).read()print u"正在下载第%d个图片" %if.write(data)f.close()#-------- 在这里输入参数 ------------------ gmurl = 'http://www.gamersky.com/news/201309/297991.shtml' items = GetPicture(gmurl,1,14) Download_Pictures(items)