CasperJS : 为什么我的网址在加载页面时更改为 about:blank
CasperJS : Why does my url change to about:blank when my page is loaded?
我是PhantomJS/CasperJS的初学者。
我只想启动一个会话并验证它是否正常。
这是我的代码:
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: false,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0'
}
});
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
});
casper.on("page.error", function(msg,trace) {
this.echo("Page Error: " + msg, "ERROR");
});
casper.start('https://www.google.fr');
casper.then(function(){
console.log('Page Loaded');
this.test.assertTitle('Google', 'Welcome to Google');
});
casper.run();
当我运行这个简单的脚本时,我得到:
C:'Users'Booky'Documents'nike_project>casperjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 debug.js
C:'Users'Booky'Documents'nike_project>[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: https://www.google.fr/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.google.fr/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://www.google.fr/"
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] start page is loaded
[info] [phantom] Step anonymous 3/3 https://www.google.fr/ (HTTP 200)
Page Loaded
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"
我到处搜索,都没有找到对我的问题的任何回应。
<小时 />环境
- 幻影 2.1.1
- CasperJS 1.1.0beta5
CasperJS和PhantomJS Github Repos上存在关于重定向/打开的未解决的问题(请参阅下面的更新) about:空白页
-
问题 13738 Phantomjs 打开一个关于:空白页面,而不是 URL
-
问题 1485 重定向至 url=about:blank
2017年3月9日更新:问题1485已解决。有关解决方案,请参阅 GitHub 上的@jefleponot评论
我自己还没有确认,但@Ross评论说,为phantomjs添加选项--ssl-protocol=any解决了问题
- --
- proxy-type=none 命令行参数
在 Windows 上,默认代理设置可能会导致庞大的网络 延迟(请参阅发行说明中的已知问题)。解决方法是 完全禁用代理,例如通过启动 PhantomJS --proxy-type=none 命令行参数。1
您的代码在以下版本中正常工作:
- 幻影 2.1.1
- 卡斯珀JS 1.0.4
- MacOSX
[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: https://www.google.fr/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.google.fr/, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "https://www.google.fr/"
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] start page is loaded
[info] [phantom] Step 3/3 https://www.google.fr/ (HTTP 200)
Page Loaded
PASS Welcome to Google
[info] [phantom] Step 3/3: done in 262ms.
[info] [phantom] Done 3 steps in 341ms
casperjs 1.1.x beta 和 PhantomJS>9.8 中的页面导航存在一些问题,建议将 PhantomJS 降级到 1.9.7
如果可能的话,我建议尝试不同的版本
Github 问题 1485 解决方案或@Ross解决方案都可以解决问题 - 任何评论?
我的步骤也有这个同样神秘的调试日志记录:
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"
就我而言,我需要单击AJAX表单上的"提交"按钮,该表单是带有href='javascript:;'
的链接元素。事实证明,这本身并不是主要问题。相反,他们的Web系统是使用Apache Wicket java Web框架构建的,该框架为每个搜索交互发出有状态的会话。它通过重定向发生 - 这是这里的关键点。
现在CasperJS支持两个引擎PhantomJS和SlimerJS...在深入研究 CasperJS 文档时,我缠绕了这个链接页面 SlimerJS 和 PhantomJS 之间的差异,其中指出:
"PhantomJS不做重定向,而SlimerJS做。
作为参考,这是我的选项设置为最松散并启用调试(其中一些是默认值):
var casper = require('casper').create({
engine: 'slimmerjs',
verbose: true,
logLevel: 'debug',
exitOnError: false,
ignoreSslErrors: true,
pageSettings: {
javascriptEnabled: true,
loadImages: true,
loadPlugins: true,
localToRemoteUrlAccessEnabled: true,
userAgent: 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36',
XSSAuditingEnabled: false,
logLevel: 'debug'
}
});
- confuse about the parentNode
- 将 target=“blank” 添加到带有 javascript 的链接中
- About prototype and prototypejs
- CasperJS : 为什么我的网址在加载页面时更改为 about:blank
- Dynamic about: URLs using JavaScript Code Modules (XPCOMUtil
- 在火狐浏览器中通过书签更改about:config参数
- Information about net::ERR_CONNECTION_TIMED_OUT
- Node JS - Youtube API Is Blank
- document.write(“某些文本”)会擦除 URL,并显示 about:blank
- About nodejs server.listen()
- Javascript about looping checkbox
- About getElementsByTagName
- youtube iFrame is blank
- GreaseMonkey @include for about:newtab
- about the iframe of fancybox?
- 为什么window.location.htm在chrome中返回about:black
- 从对象中取出具有无效(NaN、blank等)值的键的最佳方法
- 如何使用JavaScript将当前页面设置为about:black
- Lytebox显示"about:blank"而不是必需的链接
- Chrome扩展权限"about:blank"页面