# coding=utf-8 from bs4 import BeautifulSoup import urllib.request import os import time def downlaodimg(url): os.chdir(os.path.join(os.getcwd(), 'photos')) t = 1 # 記錄圖片張數 html_doc = urllib.request.urlopen(url).read().decode('utf-8') soup = BeautifulSoup(html_doc, "lxml") for myimg in soup.find_all('img', class_='BDE_Image'): pic_name = str(time.time()) + '.jpg' img_src = myimg.get('src') urllib.request.urlretrieve(img_src, pic_name) print("Success!" + img_src) t += 1 downlaodimg("https://tieba.baidu.com/p/2772656630")