天下三 藏宝阁
var page = require('webpage').create();
page.viewportSize = {width: 1200,height: 1500};
page.settings.useragent='Mozilla/5.0 (X11; ubuntu; linux i686; rv:48.0) Gecko/20100101 Firefox/48.0';
var webSite='https://tx3.cbg.163.com/cgi-bin/equipquery.py?act=show_overall_search';
/*
加载外部js,不过好像加载了就会和网页里的有冲突
page.includeJs(
'https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js',
function() {
waitFor(function() {
return page.evaluate(function() {
return $("#pager").children('a').length>3;
});
}, function() {
console.log("content has been load");
page.render("output.png");
phantom.exit();
},10000);
}
);
*/
//死等,会把资源抢尽,不建议
function sleep(n) {
var start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > n) {
break;
}
}
}
//等待某个目标达成后去执行某个程序
"use strict";
function waitfor(testFx, onReady, timeOutMillis) {
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, //< Default Max Timout is 3s
start = new Date().getTime(),
condition = false,
Interval = setInterval(function() {
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
// If not time-out yet and condition not yet fulfilled
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
} else {
if(!condition) {
// If condition still not fulfilled (timeout but condition is 'false')
console.log("'waitFor()' timeout");
page.render("timeout.png");
phantom.exit(1);
} else {
// Condition fulfilled (timeout and/or condition is 'true')
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
clearinterval(interval); //< Stop this interval
}
}
}, 500); //< repeat check every 250ms
};
function isCbgLoadSuss(){
return page.evaluate(function() {
return document.getelementbyid("pager").childElementCount>1;
});
}
function makeAScreen(name){
console.log("make a screenShot "+ name);
page.render(name+".png");
}
function changeAttr(type,attr)
{
page.evaluate(function(type,attr){
switch(type)
{
case 1:
document.getElementsByName("equ_xiuwei_min")[0].value=attr;
break;
case 2:
document.getElementsByName("equ_xiuwei_max")[0].value=attr;
break;
}
},type,attr);
}
page.onLoadFinished = function(status){
var script1="function(){search();}";
var script2="function(){search_role_price_down();}";
var script3="function(){search_role_price_up();}";
console.log("onLoadFinished");
changeAttr(1,85000);
page.evaluatejavaScript(script1);
waitFor(function(){return isCbgLoadSuss()}, function() {
makeAScreen("item_show");
page.evaluateJavaScript(script3);
waitFor(function(){
return isCbgLoadSuss();
},function(){
makeAScreen("price_up");
phantom.exit();
},10000);
},10000);
};
page.open(webSite, function(status){
console.log("Status:connect "+status);
if(status == "success"){
//
}
});
文章最后发布于: 2018-07-29 16:13:05
相关阅读
最近很多人都在玩支付宝里的蚂蚁森林,然后好奇也进来玩了一下,那么这个到底有什么用呢?不知道的话可以看看下面的教程。蚂蚁森林是支
胡润研究院今日发布《2018胡润大中华区独角兽指数》榜单,结合资本市场独角兽定义筛选出有外部融资且估值超十亿美金的优秀企业,累计
A5创业网(公众号:iadmin5)3月6日报道,昨日有消息称,聊天宝团队宣布就地解散,原来大约两百人的团队,只保留二三十人。这些人或将回流到锤
有不少的小伙伴因为自己在生意上的资金周转不过来的时候就会想着要去进行贷款,而作为淘宝商家,可能会选择进行淘宝信用贷款,为了帮助
2017淘宝金牌卖家条件有哪些?很多朋友抱怨淘宝金牌卖家很难做到,其实成为金牌卖家并不难,淘宝金牌卖家可以让顾客信服你的淘宝店铺