import urllib
import re
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
def getImage(html):
reg = r'src="(.*?\.jpg)"'
recmp = re.compile(reg)
imageList = re.findall(recmp,html)
x = 0
for imgurl in imageList:
urllib.urlretrieve(imgurl,"%s.jpg" % x)
x += 1
def test():
filename=open('D:\\python\\ch1\\test.txt','w')
print >> filename,"test write file"
filename.close()
def main():
html = getHtml("http://tieba.baidu.com/p/3338408181?pn=2&statsInfo=frs_pager")
getImage(html)
os.system("pause")
if __name__ == "__main__":
main()
浙公网安备 33010602011771号