python 爬取美女图片

B站影视 2024-12-12 10:15 2

摘要:import requestsimport sysimport iofrom bs4 import BeautifulSoupimport timesys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding

import requestsimport sysimport iofrom bs4 import BeautifulSoupimport timesys.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.textc_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)

来源:科技凡人说

相关推荐