python与美图,呵呵,你懂的

2023-01-31 01:01:42 python 美图 你懂

#!/usr/bin/python
import re
import urllib
#def gethtml(url):
# urllib.open(url)
def getHtml(url):
 page = urllib.urlopen(url)
 html = page.read()
 return html
def getImg(html):
 reg = r'src="(.*?\.jpg)"'
 imgre = re.compile(reg)
 imglist = re.findall(imgre,html)
# return imglist
 x = 1000
 for imgurl in imglist:
  urllib.urlretrieve(imgurl,'jpg/%s.jpg' % x)
  x+=1
  print imgurl
html = getHtml("Http://bbs.voc.com.cn/topic-5094572-1-1.html")
getImg(html)

相关文章