首页 > 代码库 > 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 下拉滚动条获取网页的全部源码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。