####主配置文件代码:getimg.py: 本文采用http://tieba.baidu.com/p/3368766768这个页面的壁纸作为范例。
#!/usr/bin/env python
#-*-coding:utf-8-*-
#Author:Nortorm
import re
import urllib
from ConfigParser import ConfigParser
CONFIGFILE = 'config.ini'
config = ConfigParser()
config.read(CONFIGFILE)
LinkPath = config.get("UrlLinkPath","Linkpath")
def gethtml(url):
page = urllib.urlopen(url)
html = page.read()
#print html
return html
def getimg(html):
reg = r'src="(.*?\.jpg)" pic_ext'
print reg
imgre = re.compile(reg)
imglist = re.findall(imgre,html)
print getimg
x = 0
for imgurl in imglist:
urllib.urlretrieve(imgurl,'%s.jpg' % x)
x+=1
html = gethtml(LinkPath)
print getimg(html)
####附属配置文件: 命名为config.ini;其中Linkpath:后面的网页地址可自行修改...(和上面文件放在一个目录,下载好的图片也在此目录下面,且以数字命名。)
[UrlLinkPath]
Linkpath: http://tieba.baidu.com/p/3368766768