下载游民的壁纸
# -*- 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 = url else: myUrl = url tmps = '_' + str(i) + '.shtml' myUrl = string.replace(myUrl, '.shtml' , tmps) print myUrl myResponse = 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 items def 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个图片" %i f.write(data) f.close() #-------- 在这里输入参数 ------------------ gmurl = 'http://www.gamersky.com/news/201309/297991.shtml' items = GetPicture(gmurl,1,14) Download_Pictures(items)
posted on 2013-10-02 20:57 walkwalkwalk 阅读(330) 评论(0) 编辑 收藏 举报