標籤:doc mobile cookies hive version os x 分享 自動 setting
之前為了抓取興趣部落裡的資料,研究了下QQ自動登入。
當時搜尋了一番,發現大部分方法都已經失效了,於是準備自己開搞。
第一個想到的就是參考網上已有方案的做法,梳理登陸js的實現,通過其他語言重寫。
考慮到js可能會更新,放棄了此方案。
第二個想到的是能不能直接調用QQ自己的js方法,類比進行提交呢。
搜尋一番後發現神器 ———— "phantomjs".
PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
於是開搞,代碼實現如下。
var page = require(‘webpage‘).create();var fs = require("fs");page.settings.userAgent = ‘Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4‘;page.open(‘http://ui.ptlogin2.qq.com/cgi-bin/login?pt_no_onekey=1&style=9&appid=1006102&s_url=http%3A%2F%2Fxiaoqu.qq.com%2Fmobile%2Fbarindex.html%3F_lv%3D29313%26_bid%3D128%26_wv%3D1027%26from%3Dshare_link%23bid%3D37469%26type%3D%26source%3Dindex%26scene%3Drecent%26from%3Ddongtai%26webview%3D1&low_login=0&hln_css=http%3A%2F%2Fpub.idqqimg.com%2Fqqun%2Fxiaoqu%2Fmobile%2Fimg%2Fnopack%2Flogin-logo.png‘, function(status){ if (status == ‘success‘) { page.render(‘index.png‘); setTimeout(function() { page.evaluate(function() { document.getElementById(‘u‘).value = ‘QQ號碼‘; document.getElementById(‘p‘).value = ‘QQ密碼‘; pt.check(false); }); setTimeout(function() { file = fs.open("cookie.log", ‘w‘); file.write(JSON.stringify(page.cookies)); file.close(); phantom.exit(); }, 2000); }, 1000); }});
cookie會寫入到目前的目錄下的cookie.log檔案,有了cookie接下來的事情就簡單多了。使用php或js將cookie種到瀏覽器下即可。
附:
下載phantomjs的Windows版本:http://phantomjs.org/download.html
在當前檔案夾下運行cmd命令:1. 在案頭上先按住Shift鍵,然後滑鼠右鍵,出現選項“在此處開啟命令視窗(W)”也可以開啟命令列。2. 點擊“在此處開啟命令視窗(W)”,進入CMD命令列介面。 參考文章:利用phantomjs類比QQ自動登入:https://www.liudon.org/1327.htmlQQ類比登入實現之四兩撥千斤(基於V8引擎):http://ju.outofmemory.cn/entry/246396PhantomJS在Windows7下實現網站自動下載(包含PhantomJS在Windows7下的安裝):http://www.cnblogs.com/huangcong/archive/2013/04/18/3027654.html
利用phantomjs類比QQ自動登入