CasperJS:为什么在加载页面时,我的URL更改为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"
我到处搜索,但没有找到解决我问题的答案.
环境
- PhantomJS 2.1.1
- CasperJS 1.1.0beta5
CasperJS和PhantomJS Github Repos上存在有关重定向到/打开about:空白页面的未解决问题(请参阅下面的更新) >
-
2017年3月9日更新:解决了1485问题.请参见 1
您的代码在以下版本中正常工作:
- PhantomJS 2.1.1
- CasperJS 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> 1.9.8中的页面导航存在一些问题,建议将PhantomJS降级到1.9.7
如果可能的话,我建议尝试不同的版本
Github Issue 1485解决方案或@Ross解决方案都可以解决问题-有任何评论吗?
I'm a beginner at PhantomJS/CasperJS.
I just want to start a session and verify that it's OK.
Here's my code:
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();
When I run this simple script, I get :
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"
I searched everywhere and I haven't found any response to my problem.
Environment
- PhantomJS 2.1.1
- CasperJS 1.1.0beta5
解决方案There are open issues (see update below) on CasperJS and PhantomJS Github Repos regarding redirecting to/opening about:blank page
Issue 13738 Phantomjs opens a about:blank page instead of the URL
Issue 1485 Redirect to url=about:blank
Updated on March 09 2017: Issue 1485 solved. See @jefleponot comment on GitHub for the solution
Haven't confirmed it myself, but @Ross commented that adding the option --ssl-protocol=any for phantomjs solved the issue
- --proxy-type=none command-line argument
On Windows, the default proxy setting may cause a massive network latency (see Known Issues in the release note). The workaround is to disable proxy completely, e.g. by launching PhantomJS with --proxy-type=none command-line argument. 1
Your code worked correctly, with the following versions :
- PhantomJS 2.1.1
- CasperJS 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
There were some issues with page navigation in casperjs 1.1.x beta and PhantomJS >1.9.8 where the recommendation was to downgrade PhantomJS to 1.9.7
I would recommend, if possible, to try different versions
Either Github Issue 1485 solution or @Ross solution may solve the problem - any comments?
这篇关于CasperJS:为什么在加载页面时,我的URL更改为about:blank?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!