爬妹纸图
import requests
from bs4 import BeautifulSoup
n=1
headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36"}
url = "https://www.tupianzj.com/meinv/mm/meizitu/"
r = requests.get(url,headers=headers)
r.encoding = "GBK"
#print(r.text)
soup = BeautifulSoup(r.text,"html.parser")
div_list = soup.find("div",class_="list_con_box").find_all("a",target="_blank")
for div in div_list:
child_url = "https://www.tupianzj.com" + div.get("href")
content = requests.get(child_url,headers=headers)
content.encoding = "GBK"
soup_1 = BeautifulSoup(content.text,"html.parser")
jpg_src = soup_1.find("div",id="bigpic").find("img",id="bigpicimg").get("src")
with open(f"{n}.jpg",mode="wb") as f:
f.write(requests.get(jpg_src).content)
print("一张图片下载完成")
n += 1