首页 > 代码库 > phantomjs 下拉滚动条获取网页的全部源码

phantomjs 下拉滚动条获取网页的全部源码

//codes.js  
var system = require(‘system‘); 
var fs = require("fs"); 
//console.log(‘Loading a web page‘);  
var page = require(‘webpage‘).create();  
var url = "https://m.rong360.com/shenyang/search?loan_limit=3.0&application_type=9&loan_term=12&rf_page_name=homepage&fr=btn";  
console.log(url);  
     page.settings = {
   userAgent: ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36‘,
  	  javascriptEnabled: true,
      loadImages: true
};
 console.log("begin");

page.viewportSize = {width:1000,height:2000};
  console.log("--------------------1------------------------------");
page.open(url, function (status) {  
    //Page is loaded!  
           if (status != "success") {
            console.log("visit web eror");
        }
        else {
          console.log("--------------------2------------------------------");
    waitFor();
// window.setTimeout(function () { 
//                  page.render(‘1.png‘);
//                console.log("---------------------FS MOVE------------------------------");
//           phantom.outputEncoding="utf8";
//                fs.write(‘1.html‘, page.content, ‘w‘);
//               phantom.exit();
//            },30000);
        }       
});   

function markCapture()
{
var ishaveA=page.evaluate(function () { 
	var flag=false;
	var acount=document.getElementsByClassName("ui-product-item").length;
	var source=document.body.innerHTML;

if(acount!=0&&document.getElementsByClassName("no-more").length==0)
{
	document.getElementsByClassName("ui-product-item")[acount-1].scrollIntoView();
}
else
{
flag=true;
}

	return flag;
  });
return ishaveA;
}

 function waitFor() {
  interval = setInterval(function() {
  	 var flag= markCapture();
  	 console.log("flag:"+flag);
  	   if(flag){
        	console.log("flag is:"+flag);
        	  page.render(‘1.png‘);
                console.log("---------------------FS MOVE------------------------------");
           phantom.outputEncoding="utf8";
                fs.write(‘1.html‘, page.content, ‘w‘);
        clearInterval(interval); 
       phantom.exit();
 }
 }, 5000); //< repeat  5000ms    
}

  

phantomjs 下拉滚动条获取网页的全部源码