参看:http://www.cnblogs.com/fnng/p/3576154.html

点击(此处)折叠或打开

  1. import urllib
  2. import re

  3. def getHtml(url):
  4.     page = urllib.urlopen(url)
  5.     html = page.read()
  6.     return html

  7. def getImg(html):
  8.     reg = r'src="(.+?\.jpg)" pic_ext'
  9.     imgre = re.compile(reg)
  10.     imglist = re.findall(imgre,html)
  11.     x = 0
  12.     for imgurl in imglist:
  13.         urllib.urlretrieve(imgurl,'%s.jpg' % x)
  14.         x +=1

  15. html = getHtml('http://tieba.baidu.com/p/2460150866')
  16. print getImg(html)

08-30 21:04