import os
import time
# 导入发送请求模块:
import requests
# 导入解析文本模块:
from bs4 import BeautifulSoup
from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
#多线程:
from threading import Thread
#多进程:
from multiprocessing import Process
#进程池:
from multiprocessing import Pool
from bs4 import BeautifulSoup
#导入cpu_count查看CPU信息获取本机CPU核数:
from multiprocessing import cpu_count
print("开始爬取")
# 返回上一级目录:
# base_path = os.path.dirname(os.path.abspath(__file__))
base_path = "D:s27day67"
# 路径和图片文件夹拼接:
img_path = os.path.join(base_path, "img")
# 获取响应:
response = requests.get("https://pinkgirl.baklib.com/4a1d/346e")
# 将请求结果交给bs4解析:
soup = BeautifulSoup(response.text, "html.parser")
# 经过分析定位到<div class="content mt-5">:
div_obj = soup.find(name="div", attrs={"class": "content mt-5"})
# print(div_obj)
div_obj1 = div_obj.find_all(name="div", attrs={"class": "editor_js--qiniu_image__picture"})
for d1 in div_obj1:
img = d1.find(name="img")
img_src = img.get("src")
img_response = requests.get(img_src)
file_path = os.path.join(img_path, img_src.rsplit("/", 1)[-1])
with open(file_path,"wb+") as f:
f.write(img_response.content)