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)
如何多线程下载图片,需要调用down函数
青龙摄影2024-07-31 20:44
相关推荐
IVEN_16 小时前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发Ray Liang17 小时前
用六边形架构与整洁架构对比是伪命题?AI攻城狮18 小时前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践千寻girling18 小时前
一份不可多得的 《 Python 》语言教程AI攻城狮21 小时前
用 Playwright 实现博客一键发布到稀土掘金曲幽21 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案孟健2 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析码路飞2 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭曲幽2 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议