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); //document.getElementById('go').click(); //pt.check()或.click() }); 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种到浏览器下即可。