TuChong_Spider
(新手爬蟲專案大牛勿噴)
偶然的機會在抖音看到這個APP,發現有很多高質量的手機桌布和圖片,對於一個爬蟲初學者,這就非常美滋滋了,好多歐美小姐姐啊,哎嘿嘿....
圖蟲網共享相簿爬蟲, 通過抓取Ajax獲取圖片ID進行圖片儲存
爬取網站: https://stock.tuchong.com
爬取結果

執行環境:
- Python 3.5+
- Windows 10
- VSCode
如何使用
下載專案原始碼
https://github.com/cexll/tuchong_Spider.git
安裝依賴
$ pip install -r requirements.txt
執行專案
$ python spider.py
輸入想要搜尋的內容: 少女
獲取圖片ID.....
解析imageID
存在ID,解析
解析HTML圖片URL...
準備下載... //p3a.pstatp.com/weili/l/199813*************89.jpg
下載成功----------------------
拼接url訪問網頁
解析HTML圖片URL...
準備下載... //p3a.pstatp.com/weili/l/189***********417.jpg
下載成功----------------------
拼接url訪問網頁
解析HTML圖片URL...
準備下載... //p3a.pstatp.com/weili/l/1**************25.png
拼接url訪問網頁
解析HTML圖片URL...
準備下載... //p3a.pstatp.com/weili/l/2***********62820.jpg
拼接url訪問網頁
解析HTML圖片URL...
準備下載... //p3a.pstatp.com/weili/l/************2.jpg
拼接url訪問網頁
...
複製程式碼
圖片連結我就大碼了,免得被打....
思路(前方高能,請流量黨注意)
首先爬取一個網頁,第一步,先開啟這個網頁(/滑稽,,,,

開啟之後,先看看怎麼搜尋圖片,下載圖片的..


嗯~~,好看山山水水...(我是來幹嘛的....
回到正題~
開啟開發者工具(F12 或者右鍵 ,然後重新整理

然後看一看有沒有什麼有用的東西....好像仔細找了找是沒有發現什麼有用的...怎麼辦呢?
好像真找不到了,怎麼辦?
網頁往下翻一翻,,,,,

圖片中間出現了個奸細
....這就是我們需要的東西,,但是開啟發現不對啊,怎麼沒有圖片下載的連結??

哎,別慌,先去網頁開啟一個圖片看看是什麼結構的...

到這裡我們發現了,網頁url連結有個imageID=
這東西,好像和之前找到個奸細內容是一樣的,,,開啟後發現的確是一樣的
那麼整體的結構就清楚了,先把剛才的奸細連結開啟看看是什麼


密集恐懼症都犯了,....仔細看了看,發現最開始都有imageID
,那麼思路就有了
通過訪問奸細的連結得到每一頁的imageID
,在用 https://stock.tuchong.com/free/image/? + imageID
就可以訪問到圖片了,好一氣呵成
程式碼
完整程式碼見專案地址: github.com/cexll/tucho…


總結
抓取所有的網頁都是類似的思路,首先先通過人的邏輯去找到資料,在通過程式碼去得到,不要一來就上手程式碼,
細心的朋友肯定發現了,我們抓的是免費相簿裡的圖片,是的,至於為什麼不抓優選相簿,高階相簿,1是我也是才發現他們不一樣,2是別人賺錢的生意我就這樣發出來了萬一被抓了怎麼辦....
有能力的可以自己去琢磨一下,我上次看了一下imageID這次是儲存在HTML裡面的,有點類似今日頭條的
專案地址: github.com/cexll/tucho…