import requests
from bs4 import BeautifulSoup
import time
url = "http://www.jj20.com/bz/nxxz/"
resp = requests.get(url)
resp.encoding = 'gbk'
main_page = BeautifulSoup(resp.text, "html.parser")
alist = main_page.find("ul", class_="picbz").find_all("a")
for a in alist:
href = a.get('href')
hreft = "http://www.jj20.com" + href
child_page_resp = requests.get(hreft)
child_page_resp.encoding = 'gbk'
child_page_text = child_page_resp.text
child_page = BeautifulSoup(child_page_text, "html.parser")
img = child_page.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("over!", img_name)