Python爬蟲入門案例之回車桌面壁紙網(wǎng)美女圖片采集
知識(shí)點(diǎn)
- requests
- parsel
- re
- os
環(huán)境
- python3.8
- pycharm2021
目標(biāo)網(wǎng)址
https://mm.enterdesk.com/bizhi/63899-347866.html

【付費(fèi)VIP完整版】只要看了就能學(xué)會(huì)的教程,80集Python基礎(chǔ)入門視頻教學(xué)
注意: 在我們查看網(wǎng)頁源代碼的時(shí)候 (1. 控制臺(tái)為準(zhǔn) 2. 以右鍵查看網(wǎng)頁源代碼 3. 元素面板)
- 發(fā)送網(wǎng)絡(luò)請求
- 獲取網(wǎng)頁源代碼
- 提取想要的圖片鏈接 css樣式提取 xpath re正則表達(dá)式 bs4
- 替換所有的圖片鏈接 換成大圖
- 保存圖片
爬蟲代碼
導(dǎo)入模塊
import requests # 第三方庫 pip install requests import parsel # 第三方庫 pip install parsel import os # 新建文件夾
發(fā)送網(wǎng)絡(luò)請求
response = requests.get('https://mm.enterdesk.com/bizhi/64011-348522.html')獲取網(wǎng)頁源代碼
data_html = response_1.text
提取每個(gè)相冊的詳情頁鏈接地址
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]>: 請求成功的標(biāo)識(shí)
selector = parsel.Selector(response.text)
# 提取想要的圖片鏈接[第一個(gè)鏈接, 第二個(gè)鏈接,....]
img_src_list = selector.css('.swiper-wrapper a img::attr(src)').getall()
# 新建一個(gè)文件夾
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')保存圖片 圖片名字
# 圖片 音頻 視頻 二進(jìn)制數(shù)據(jù)content
img_data = requests.get(img_url).content
# 圖片名稱 字符串分割
# 分割完之后 會(huì)給我們返回一個(gè)列表
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}頁------------------------------------')
發(fā)送網(wǎng)絡(luò)請求
response_1 = requests.get(f'https://mm.enterdesk.com/{page}.html')爬取結(jié)果



到此這篇關(guān)于Python爬蟲入門案例之回車桌面壁紙網(wǎng)美女圖片采集的文章就介紹到這了,更多相關(guān)Python 圖片采集內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
利用python實(shí)現(xiàn)簡單的情感分析實(shí)例教程
商品評論挖掘、電影推薦、股市預(yù)測……情感分析大有用武之地,下面這篇文章主要給大家介紹了關(guān)于利用python實(shí)現(xiàn)簡單的情感分析的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06
使用Python在Word文檔中添加,刪除和回復(fù)批注
在文檔協(xié)作與審閱場景中,高效管理批注是提升團(tuán)隊(duì)效率的關(guān)鍵環(huán)節(jié),下面我們就來看看如何使用Python在Word文檔中實(shí)現(xiàn)添加、刪除和回復(fù)批注的操作吧2025-03-03
聊聊PyTorch中eval和no_grad的關(guān)系
這篇文章主要介紹了聊聊PyTorch中eval和no_grad的關(guān)系,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-05-05
python處理自動(dòng)化任務(wù)之同時(shí)批量修改word里面的內(nèi)容的方法
在本篇文章里小編給各位整理的是一篇關(guān)于利用python處理自動(dòng)化任務(wù)之同時(shí)批量修改word里面的內(nèi)容的文章,需要的可以參考學(xué)習(xí)下。2019-08-08
python csv實(shí)時(shí)一條一條插入且表頭不重復(fù)問題
這篇文章主要介紹了python csv實(shí)時(shí)一條一條插入且表頭不重復(fù)問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05

