50,530
社区成员
发帖
与我相关
我的任务
分享
system = require('system')
address = system.args[1];//获得命令行第二个参数 接下来会用到
var page = require('webpage').create();
page.settings.resourceTimeout = 30000 ;
page.settings.XSSAuditingEnabled = true ;
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0';
page.customHeaders = {
"Connection" : "keep-alive",
"Cache-Control" : "max-age=0",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
};
page.open(address, function(status){
if (status !== 'success') {
console.log('Unable to access network');
phantom.exit();
} else {
var aa=document.querySelectorAll('span');
for (var i=0;i<aa.length;i++){
aa[i].click();
}
console.log('22222222222222');
window.setTimeout(function () {
console.log(page.content);
phantom.exit();
}, 10000);
phantom.exit();
}
});
public static String getAjaxCotnent(String url) throws IOException {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("D:\\phantomjs\\bin\\phantomjs.exe C:\\Users\\Administrator\\Desktop\\test.js "+url);
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer sbf = new StringBuffer();
String tmp = "";
while((tmp = br.readLine())!=null){
sbf.append(tmp);
}
System.out.println(sbf.toString());
return sbf.toString();
}
public static void main(String[] args) throws IOException {
getAjaxCotnent("https://market.m.taobao.com/apps/market/toutiao/portal.html?wh_weex=true&data_perfetch=true");
}