import urllib
from bs4 import BeautifulSoup
url= “https://tieba.baidu.com/p/2772656630”
def get_content(url):
html = urllib.urlopen(url)
content = html.read()
html.close()
return content
def get_images(info):
soup = BeautifulSoup(info,”lxml”)
all_imag = soup.find_all(‘img’,class_=”BDE_Image”)
x = 1
#return [img[‘src’]for img in all_imag]
for img in all_imag:
print img
image_name = ‘%s.jpg’ % x
urllib.urlretrieve(img[‘src’],image_name)
x+=1
info = get_content(url)
get_images(info)