python 爬取美女图片
import requests
import sys
import io
from bs4 import BeautifulSoup
import time
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
url = 'https://www.umei.cc/bizhitupian/weimeibizhi/'
resp = requests.get(url)
resp.encoding = 'utf-8'
page = BeautifulSoup(resp.text, 'html.parser')
main_div = page.find('div', attrs={'class', 'TypeList'}).find_all("a")
for i in main_div:
href = i.get("href")
c_resp = requests.get(href)
c_resp.encoding = 'utf-8'
c_page_txt = c_resp.text
c_page = BeautifulSoup(c_page_txt, 'html.parser')
p = c_page.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)
time.sleep(1)