import requests from bs4 import BeautifulSoup import time
url = "https://www.umei.cc/bizhitupian/weimeibizhi/" resp = requests.get(url) resp.encoding = 'utf-8'
main_page = BeautifulSoup(resp.text, "html.parser") alist = main_page.find("div", class_="TypeList").find_all("a")
for a in alist: href = a.get('href') child_resp = requests.get(href) child_resp.encoding = 'utf-8' child_text = child_resp.text child = BeautifulSoup(child_text, "html.parser") p = child.find("p", align="center") img = p.find("img") src = img.get("src") img_resp = requests.get(src) img_name = src.split("/")[-1] with open("img/"+img_name, mode="wb") as f: f.write(img_resp.content)
print("正在下载", img_name) time.sleep(1)
print("下载完了")
|