import reimport urllibdef get_content(url): '''doc.''' html = urllib.urlopen(url) content = html.read() html.close() return contentdef get_image(info): '''doc.''' regex = r'class="BDE_Image" src="(.+?\.jpg)"' pat = re.compile(regex) image_code = re.findall(pat,info) i = 0 for image_url in image_code: print image_url urllib.urlretrieve(image_url,'%s.jpg'%i) i += 1 return image_codeurl = 'https://tieba.baidu.com/p/27726566630'info = get_content(url)# print infoprint get_image(info)
来源:https://www.cnblogs.com/NightShade-Cwh/p/7681292.html