import re
import urllib2
import urllib
def getContext(url):
‘‘‘
获取html
‘‘‘
html = urllib2.urlopen(url)
return html.read()
def getPicture(html):
‘‘‘
获取图片网址
‘‘‘
regex = r‘class="BDE_Image" src="(.+?\.jpg)"‘
pattern = re.compile(regex)
imageUrl = re.findall(pattern, html)
i = 1
for url in imageUrl:
print url
urllib.urlretrieve(url, ‘%s.jpg‘ % i)
i +=1
url = ‘http://tieba.baidu.com/p/3932177087‘
if __name__==‘__main__‘:
html = getContext(url)
getPicture(html)
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/weiyongxuan/article/details/47208699