採集器經驗

需要得到webmaster的外鏈列表, 而webmaster api沒有提供這個數據的獲取方法, 只能寫採集器了

以前沒寫過需要用戶登錄的採集器, 先拿一些簡單的來試試

首先試了bccn, POST數據有username和password, 成功了


百度和google的登錄頁面都是https, POST時會出現錯誤, 解決方法是

http://stackoverflow.com/questions/560804/how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-using-https


但百度的POST還會出現錯誤, underlying connection was closed, the connection was closed unexpectedly.

google的POST總返回登錄頁面的內容, 看了這篇文章(http://everydayscripting.blogspot.com/2009/10/python-fixes-to-google-login-script.html)才知道: google的POST數據中有兩個得到登錄頁面提取:dsh和GALX

提取出來然後POST便返回: Your browser's cookie functionality is turned off. Please turn it on.

發現這個response的header的Set-Cookie中只有GAPS這一項(而firebug捕獲的POST response的Set-Cookie中有NID, SID, LSID, SSID, HSID, APISID, )再來看firebug捕獲的登錄POST的request的cookie裏面已經有了GAPS, 而我的提交的request沒有設置任何cookie, 所以可能是看到我的request的cookie中沒有GAPS, 便得出我把瀏覽器的cookie給關了的結論

接着實驗了下, 把cookie清空然後訪問登錄頁面, 發現response的set-cookie爲GAPS, 即POST之前需要有GAPS這個cookie.

根據上面的, 先GET一次登錄頁面獲取cookie, 然後把cookie作爲下次POST的cookie, 登錄成功了, 進了Accounts Overview頁面, 但是response裏面沒有任何cookie..

這次response html中有:

You are using an old browser version which Google accounts no longer supports. Some features may not work correctly. Please upgrade to a modern browser, such asGoogle Chrome.

不是功能不支持, 而是瀏覽器過老. 我能想到的看瀏覽器版本什麼的只有user agent了(js: navigator.userAgent)

加上userAgent然後POST, 得到的response頁面是Account settings頁面, 但仍然沒有set-cookie..

把response html加載到webbrowser中(browser.navigateToString()), 出現js錯誤, 而該頁面的js已經被壓縮了, 根本沒法看


後來又發現有一個post parameter沒加上去(checkConnection=youtube:1012:1), 加上之後立即發生WebException:Unable to connect the remote server.   inner exception是:{"由於連接方在一段時間後沒有正確答覆或連接的主機沒有反應,連接嘗試失敗。 46.82.174.68:443"}


現在打算用webbrowser來模擬登錄然後採集, 原理和之前的youku投票的firefox插件差不多, 寫到採集器(2)裏

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章