- #coding:utf8
- import re
- import urllib
- def gethtml(url):
- page = urllib.urlopen(url)
- html = page.read()
- return html
- slider
- def getImg(html,imgType):
- reg = r'src="(.*?\\.+'+imgType+'!slider)" '
- imgre = re.compile(reg)
- imgList = re.findall(imgre, html)
- x=0
- for imgurl in imgList:
- print imgurl
- urllib.urlretrieve(imgurl, '%s.%s' % (x, imgType))
- x =x+1
- html= getHTML("http://www.CodeSnippet.cn/list.html")
- getImg(html,'jpg')
- #该片段来自于http://www.codesnippet.cn/detail/110320148972.html
来源: http://www.codesnippet.cn/detail/110320148972.html