HifJzoc9
和 HM4hUBT0dDOn80T
的獲取思路
第一個
直接去看控制檯請求,就會找到下面的這個請求,這個請求返回的就是列表內容python

可是直接去找 HifJzoc9
是找不到。說明這是被後來加上去的。經過攔截 XMLHttpRequest
,將生成的參數加到請求參數裏。並且在這個網站,這個參數的名字也是 js
動態生成。web
下圖是 cookie
中 80T
的名字的生成地方。看好了就是名字。不要想太多。具體破解還未完成。chrome

因此呢一種是增長 XHR 斷點,另外一種就是使用下面的函數。這個函數我使用的時候是用谷歌插件的方式。跨域
分享一個鉤子函數瀏覽器
var code = function () { var open = window.XMLHttpRequest.prototype.open; window.XMLHttpRequest.prototype.open = function open(method, url, async) { if (url.indexOf("HifJzoc9") > -1) { debugger; } };};var script = document.createElement('script');script.textContent = '(' + code + ')()';(document.head || document.documentElement).appendChild(script);script.parentNode.removeChild(script);
這個函數能夠請求發送以前將該請求攔截。安全
既然能夠攔截到請求,那就意味能夠拿到當前環境下生成的加密參數。微信
若是常常看這個網站的話,你就會注意到,他會每隔幾秒就會發起這樣的請求cookie

因此個人攔截代碼就能夠一直使用,一直攔截不讓他發起請求。從下圖就能夠看到,請求並無發出去。app
取消請求scrapy
window.XMLHttpRequest.abort();

url
參數取到了,就差 cookie
了。
第二個
直接在控制檯打印 cookie

這樣打印出來實際上是隻有 80T
的,並無 80S.
這是由於 HTTPOnly
的緣由。具體的能夠去百度查查,如今基本大網站都有這個,也是爲了安全

這個能夠使用谷歌插件解決,能夠看看谷歌文檔。
谷歌插件提供了一個方法。固然這個方法須要在背景頁中使用。填寫 URL後就能夠獲取他的全部 cookies
。
chrome.cookies.getAll({url: "http://*.cn/"}, function (cookies) {});
80T
也是一直在刷新的,因此只須要一直獲取提交到你的爬蟲就完成了。
總結
一、攔截 XMLHTTPRequest
請求
二、獲取到已經生成加密的參數後的 url

三、取消請求
window.XMLHttpRequest.abort();
四、獲取 cookie

五、將獲取到 cookie 和 url
發送給爬蟲。(這一塊都是經過插件的背景頁作的。網站有跨域限制,因此最後的發送操做都是在背景頁。具體的你們多看看插件,挺簡單的)

六、爬蟲請求數據。

完整流程
谷歌插件 發送加密後的 url
以及 cookie
到接口,爬蟲經過接口獲取到值進行數據抓取。很簡單。
並且這網站只要你能獲取到這兩個東西,剩下就好說了,請求多了目前發現就只有個圖片驗證碼。
缺點就是:
若是須要大量抓取的話,就須要不少瀏覽器。
優勢就是:
不用破解 js
還有一種思路就是經過 selenium 、pyppeteer、puppeteer
執行 js
,生成加密參數後,再取消請求。這樣就會更快的生成你想要的東西。也是挺爽的。

可是這種的我不知道如何再去取消請求,而且將參數攔截獲取出來。若是有大佬知道的,給我指點一下,很是感謝!
本文分享自微信公衆號 - Python爬蟲scrapy(python_scrapy)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。