如何多线程下载图片,需要调用down函数

复制代码
import requests
from bs4 import BeautifulSoup
from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor

# url = 'https://www.umei.cc/meinvtupian/meinvxiezhen/'
def down(url):
    headers = {
        'authority': 'www.umei.cc',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'accept-language': 'zh-CN,zh;q=0.9',
        'cache-control': 'max-age=0',
   
        'referer': 'https://www.umei.cc/bizhitupian/',
        'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'sec-fetch-dest': 'document',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-user': '?1',
        'upgrade-insecure-requests': '1',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36',
    }

    response = requests.get(url, cookies=cookies, headers=headers)
    response.encoding="utf-8"

    soup =BeautifulSoup(response.text,'lxml')
    photos = soup.select("div.title a")

    for p in photos:
         p_url = p['href'].split("=")[-1]
         pnurl = "https://www.umei.cc/"+p_url
         p_name =p.text
         print(pnurl,p_name)
         res = requests.get(url=pnurl,cookies=cookies, headers=headers)
         res.encoding=("utf-8"),
         soup = BeautifulSoup(res.text, 'lxml')
         pp = soup.select("div.big-pic a img")[-1]
         pp_url=pp.get('src')
         res1 = requests.get(url=pp_url, cookies=cookies, headers=headers)
         open(f'img/{p_name}.jpg','wb').write(res1.content)

if __name__ == "__main__":
    with ThreadPoolExecutor(10) as t:
        for i in range(1,217):
            url = f'https://www.umei.cc/meinvtupian/rentiyishu/index_{i}.htm'
            t.submit(down,url)
相关推荐
喜欢吃豆7 分钟前
从指令遵循到价值对齐:医疗大语言模型的进阶优化、对齐与工具集成综合技术白皮书
人工智能·python·语言模型·自然语言处理·大模型·强化学习·constitutional
Access开发易登软件15 分钟前
Access调用Azure翻译:轻松实现系统多语言切换
后端·python·低代码·flask·vba·access·access开发
yumgpkpm17 分钟前
CMP (类Cloudera) CDP7.3(400次编译)在华为鲲鹏Aarch64(ARM)信创环境中的性能测试过程及命令
大数据·hive·hadoop·python·elasticsearch·spark·cloudera
代码小菜鸡6661 小时前
java 常用的一些数据结构
java·数据结构·python
CodeCraft Studio2 小时前
Excel处理控件Aspose.Cells教程:使用 Python 将 HTML 转换为 Excel
python·html·excel·aspose·aspose.cells·html转excel
王中阳Go2 小时前
Python 的 PyPy 能追上 Go 的性能吗?
后端·python·go
Goboy3 小时前
控制仙术流程 - 抉择与循环的艺术
后端·python
麦麦大数据3 小时前
F024 vue+flask电影知识图谱推荐系统vue+neo4j +python实现
vue.js·python·flask·知识图谱·推荐算法·电影推荐
AI小云3 小时前
【Python与AI基础】Python编程基础:读写CSV文件
人工智能·python
Goboy3 小时前
Python修仙入门 - 踏入仙门的第一步
后端·python