zoukankan      html  css  js  c++  java
  • 爬私房摄交圈.py

    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)
  • 相关阅读:
    数组的空位
    数组方法之pop
    数组方法之push
    深拷贝
    浅拷贝
    手动编写用于react项目开发的的webpack配置文件
    ES6:export default 和 export 区别
    JS基础算法题(二)
    Linux系统下用户如何膝盖FTP用户密码
    Sublime Text 3 安装插件与快捷键总结
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12283474.html
Copyright © 2011-2022 走看看