爬取美女图片并保存本地和多线程部分
多线程
import requests
from concurrent.futures import ThreadPoolExecutor
from lxml import html
etree = html.etree
def get_list(url):
etree = html.etree
list_resp = requests.get(url)
list_resp.encoding = "utf-8"
tree = etree.HTML(list_resp.content)
list_gg = tree.xpath('//div[@class="item-media entry"]//a')
with ThreadPoolExecutor(10) as t:
for gg in list_gg[2:16]:
if gg.xpath('./@title')[0] != '': #标题不为空
gg_title = gg.xpath('./@title')[0]
gg_href = "https://www.mn52.com"+gg.xpath('./@href')[0]
print(gg_href,gg_title)
t.submit(get_download,gg_href,gg_title) #多线程
# get_download(gg_href,gg_title)
def get_download(gg_href,gg_title):
etree = html.etree
png_resp = requests.get(gg_href)
png_resp.encoding = 'utf-8'
tree = etree.HTML(png_resp.content)
png_urls = tree.xpath('//div[@id="originalpic"]//img/@src')
number = 1
with ThreadPoolExecutor(10) as t:
for png_url in png_urls:
png_url = "https:" + png_url
png_name = gg_title + str(number)
number =int(number)+1
with open("美女图片/" + png_name+".png", mode="wb") as f:
png_down = requests.get(png_url)
f.write(png_down.content) # 图片内容写入文件
print(f"{png_name}下载成功",)
if __name__ == '__main__':
get_list("https://www.mn52.com/xingganmeinv/")
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~