【Python爬虫】回车桌面壁纸网站美女图片采集
知识点
- requests
- parsel
- re
- os
- python3.8
- pycharm2021
https://mm.enterdesk.com/bizhi/63899-347866.html
- 发送网络请求
- 获取网页源代码
- 提取想要的图片链接
css样式提取 xpath re正则表达式 bs4 - 替换所有的图片链接 换成大图
- 保存图片
import requests # 第三方库 pip install requests import parsel # 第三方库 pip install parsel import os # 新建文件夹
response = requests.get('https://mm.enterdesk.com/bizhi/64011-348522.html')
data_html = response_1.text
selector_1 = parsel.Selector(data_html) photo_url_list = selector_1.css('.egeli_pic_dl dd a::attr(href)').getall() title_list = selector_1.css('.egeli_pic_dl dd a img::attr(title)').getall() for photo_url, title in zip(photo_url_list, title_list): print(f'*****************正在爬取{title}*****************') response = requests.get(photo_url) # <Response [200]>: 请求成功的标识 selector = parsel.Selector(response.text) # 提取想要的图片链接[第一个链接, 第二个链接,....] img_src_list = selector.css('.swiper-wrapper a img::attr(src)').getall() # 新建一个文件夹 if not os.path.exists('img/' + title): os.mkdir('img/' + title)
for img_src in img_src_list: # 字符串的替换 img_url = img_src.replace('_360_360', '_source')
# 图片 音频 视频 二进制数据content img_data = requests.get(img_url).content # 图片名称 字符串分割 # 分割完之后 会给我们返回一个列表 img_title = img_url.split('/')[-1] with open(f'img/{title}/{img_title}', mode='wb') as f: f.write(img_data) print(img_title, '保存成功!!!')
page_html = requests.get('https://mm.enterdesk.com/').text counts = parsel.Selector(page_html).css('.wrap.no_a::attr(href)').get().split('/')[-1].split('.')[0] for page in range(1, int(counts) + 1): print(f'------------------------------------正在爬取第{page}页------------------------------------') 发送网络请求 response_1 = requests.get(f'https://mm.enterdesk.com/{page}.html')
标签:
Python案例教学
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了