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
相关推荐
花酒锄作田1 天前
使用 pkgutil 实现动态插件系统前端付豪1 天前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件曲幽1 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话老赵全栈实战1 天前
Pydantic配置管理最佳实践(一)阿尔的代码屋1 天前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 AgentAI探索者2 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南AI探索者2 天前
LangGraph 入门:构建带记忆功能的天气查询 AgentFishCoderh2 天前
Python自动化办公实战:批量重命名文件,告别手动操作躺平大鹅2 天前
Python函数入门详解(定义+调用+参数)曲幽2 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)