- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在这里发现了很多关于此的问题,但不确定为什么没有人回答。
我在使用此代码登录后尝试抓取网页:source
var steps=[];
var testindex = 0;
var loadInProgress = false;//This is set to true when a page is still loading
/*********SETTINGS*********************/
var webPage = require('webpage');
var page = webPage.create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36';
page.settings.javascriptEnabled = true;
page.settings.loadImages = false;//Script is much faster with this field set to false
phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;
/*********SETTINGS END*****************/
console.log('All settings loaded, start with execution');
page.onConsoleMessage = function(msg) {
console.log(msg);
};
/**********DEFINE STEPS THAT FANTOM SHOULD DO***********************/
steps = [
//Step 1 - Open Amazon home page
function(){
console.log('Step 1 - Abrindo página de login');
page.open("http://parceriascury.housecrm.com.br", function(status){
});
},
//Step 3 - Populate and submit the login form
function(){
console.log('Step 3 - Preenchendo o form');
page.evaluate(function(){
document.getElementById("login").value="xxxxx";
document.getElementById("senha").value="xxxxx";
document.getElementById("frmlandingpage").submit();
});
},
//Step 4 - Wait Amazon to login user. After user is successfully logged in, user is redirected to home page. Content of the home page is saved to AmazonLoggedIn.html. You can find this file where phantomjs.exe file is. You can open this file using Chrome to ensure that you are logged in.
function(){
console.log("Step 4 - Wait Amazon to login user. After user is successfully logged in, user is redirected to home page. Content of the home page is saved to AmazonLoggedIn.html. You can find this file where phantomjs.exe file is. You can open this file using Chrome to ensure that you are logged in.");
var fs = require('fs');
var result = page.evaluate(function() {
return document.documentElement.outerHTML;
});
fs.write('C:\\phantomjs\\logado_cury_10.html',result,'w');
},
];
/**********END STEPS THAT FANTOM SHOULD DO***********************/
//Execute steps one by one
interval = setInterval(executeRequestsStepByStep,5000);
function executeRequestsStepByStep(){
if (loadInProgress == false && typeof steps[testindex] == "function") {
//console.log("step " + (testindex + 1));
steps[testindex]();
testindex++;
}
if (typeof steps[testindex] != "function") {
console.log("test complete!");
phantom.exit();
}
}
/**
* These listeners are very important in order to phantom work properly. Using these listeners, we control loadInProgress marker which controls, weather a page is fully loaded.
* Without this, we will get content of the page, even a page is not fully loaded.
*/
page.onLoadStarted = function() {
loadInProgress = true;
console.log('Loading started');
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log('Loading finished');
};
page.onConsoleMessage = function(msg) {
console.log(msg);
};
但响应只有这个:
<html><head></head><body>ok</body></html>
我需要使用 URL 获取下一页的内容:
http://parceriascury.housecrm.com.br/parceiro_busca
我可以直接访问这个页面,但不是所有的补充,因为它需要登录。
没有错误,我不知道我在哪里犯了错误。
编辑欢迎使用其他解决方案,我想可能是 curl
...但是在加载 js 之后...
抱歉我的英语不好。
最佳答案
这段代码可能会更好:
var loadInProgress = false;//This is set to true when a page is still loading
/*********SETTINGS*********************/
var page = require('webpage').create({viewportSize:{width: 1600,height: 900},
settings:{userAgent:'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36',
javascriptEnabled:'true',
loadImages:'false'
}});
var fs = require('fs');
/*********SETTINGS END*****************/
console.log('All settings loaded, start with execution');
/**
* These listeners are very important in order to phantom work properly. Using these listeners, we control loadInProgress marker which controls, weather a page is fully loaded.
* Without this, we will get content of the page, even a page is not fully loaded.
*/
page.onLoadStarted = function() {
loadInProgress = true;
console.log('Loading started');
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log('Loading finished');
};
page.onConsoleMessage = function(msg) {
console.log(msg);
};
//Log in to your account, then view the cookie you got, now you can use these cookies to login
// the site will recognize you with your cookies.
//for freebitco.in auth
phantom.cookies = [{// an array of objects
'name' : 'btc_address',
'value' : '1AuMxR6sPtB2Z6TkahSnpmm1H4KpYPBKqe',
'domain' : 'freebitco.in',
'path' : '/',
'httponly' : false,
'secure' : true,
'expires' : (new Date()).getTime() + (1000 * 60 * 60 * 43800) //5 years
},{ 'name' : 'password',
'value' : 'f574ca68a8650d1264d38da4b7687ca3bf631e6dfc59a98c89dd2564c7601f84',
'domain' : 'freebitco.in',
'path' : '/',
'httponly' : false,
'secure' : true,
'expires' : (new Date()).getTime() + (1000 * 60 * 60 * 43800) }]
//Execute steps one by one
page.open("http://parceriascury.housecrm.com.br/parceiro_busca", function(status){
console.log('Step 1 has been completed - we are on the target page!');
setTimeout(step2,5000);// Maybe we don't need to wait here, we can execute step2 immediately.
function step2(){
console.log("Step 2 - Content of the home page is saved to AmazonLoggedIn.html. You can find this file where phantomjs.exe file is. You can open this file using Chrome to ensure that you are logged in.");
var result = page.evaluate(function(){ return document.documentElement.outerHTML; });
fs.write('C:\\phantomjs\\logado_cury_10.html',result,'w');
phantom.exit();
}
});
关于javascript - 使用 PhantomJs 登录后如何进入下一页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40880785/
我正在尝试开始使用 Mermaid CLI,但是当我尝试针对我的源文件运行它时,它说找不到 phantomjs。 (我运行的是 Win 7 64。) C:\Users\Chris\Documents>
我正在使用PhantomJS来调用网页,如下所示: page.open('http://example.com', function (s) { console.log(page.content)
如果有这样的功能,我需要更改Phantomjs自动清除缓存的默认时间。有什么想法吗? 最佳答案 应该是您正在寻找的功能: https://github.com/ariya/phantomjs/issu
我想从我的程序运行 PhantomJs 脚本,但由于脚本可能不是我写的,我需要确保 PhantomJs 在执行完成或因任何原因(例如无效语法、超时、 ETC)。到目前为止,我读到的所有内容都说你必须始
在 Package JSON 中,我尝试了许多不同版本的 karma-phantomjs-launcher、phantomjs,包括 phantomjs-prebuilt。 当前包 JSON “开发依
我的脚本有一些语法错误,但 PhantomJS 没有显示任何错误,而是没有显示任何内容。如果脚本有错误,为什么 Phantom JS 不显示解析错误? 在以下 PhantomJS 脚本(通过 Wind
我有一些需要填写的动态输入表单。问题是要填写表格,我需要访问另一个页面以获取取决于上一页输入的数据。因此,在我获得数据然后返回表单后,表单已经更改,因此我需要在获取数据时保持该表单打开。那么问题是如何
PhantomJS 在为我捕获网页到图像文件方面做得很好。我正在使用基于 rasterize.js 的脚本。 但是,对于某些固定大小的 Web 元素,我需要生成的图像与 Web 元素的大小相匹配。 例
我正在将 PhantomJS headless 浏览器集成到我的一个项目中(目前使用 1.6 版)。在大多数情况下,它在完成我需要完成的工作方面做得很好。但是,WebPage.open() 调用工作方
是否可以在page.evaluate中传递变量? function myFunction(webpage, arg1, arg2){ var page = require('webpage').cre
有没有办法始终如一地检测 PhantomJS/CasperJS?我一直在处理用它构建的一系列恶意垃圾邮件机器人,并且能够根据某些行为基本上阻止它们,但是我很好奇是否有一种坚如磐石的方法来了解 Casp
有没有办法拦截资源请求并直接从处理程序给出响应?像这样的事情: page.onRequest(function(request){ request.reply({data: 123}); });
phantomjs 有配置 loadImage, 但我想要更多, 如何控制phantomjs跳过下载某种资源, 比如css等... ===== 好消息:已添加此功能。 https://code.goo
我正在尝试在 PhantomJS (2.1.1) 的 page.evaulate() 调用中使用 WebSocket。当尝试连接到 WebSocket 服务器时,出现以下错误: 安全错误:DOM 异常
我正在使用 PhantomJS 1.8,但遇到了一个限制——您无法指定它用于磁盘缓存的目录。我将其添加到他们的问题跟踪系统中,但由于以前没有它,所以我不希望它很快添加。 因此,我正在寻找解决此限制的方
我想渲染一个仅在用户滚动页面时加载图像的页面。仅设置 page.scrollPosition 没有任何效果。我需要一些可以随时间改变滚动位置的东西。 最佳答案 不确定这是否是最好的方法,但它确实有效。
我正在尝试使用 PhantomJS 设置远程调试,但运气不佳。我按照 https://github.com/ariya/phantomjs/wiki/Troubleshooting 上的说明进行操作。
在 PhantomJS 中,webpage.open 会使用状态参数设置为“成功”或“失败”的回调。根据文档,如果没有发生网络错误,则“成功”,否则“失败”。有没有办法查看导致失败的底层网络错误? 当
有什么方法可以使用 phantomjs 请求资源并能够到达响应的主体吗? 最佳答案 更新:关于“获取并使用所有其他资源(如图像、CSS、字体等)做某事”的其他可能含义,我最近在博客上写了 how to
在运行 PhantomJS 提供的 rasterize.js 示例时,我发现我必须等待 20 秒或更长时间才能生成网页图像。 有没有可能在不消耗大量资源的情况下加快速度的方法?我基本上希望快速生成从加
我是一名优秀的程序员,十分优秀!