简体   繁体   English

CasperJS:为什么我的网址加载时会更改为:空白?

[英]CasperJS : Why does my url change to about:blank when my page is loaded?

I'm a beginner at PhantomJS/CasperJS. 我是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 PhantomJS 2.1.1
  • CasperJS 1.1.0beta5 CasperJS 1.1.0beta5

There are open issues (see update below) on CasperJS and PhantomJS Github Repos regarding redirecting to/opening about:blank page CasperJS和PhantomJS Github Repos有关于重定向到/打开的未解决的问题(请参阅下面的更新) :空白页


  • --proxy-type=none command-line argument --proxy-type = none命令行参数

On Windows, the default proxy setting may cause a massive network latency (see Known Issues in the release note). 在Windows上,默认代理设置可能会导致大量网络延迟(请参阅发行说明中的​​已知问题)。 The workaround is to disable proxy completely, eg by launching PhantomJS with --proxy-type=none command-line argument. 解决方法是完全禁用代理,例如通过使用--proxy-type = none命令行参数启动PhantomJS。 1 1


Your code worked correctly, with the following versions : 您的代码正常运行,具有以下版本:

  • PhantomJS 2.1.1 PhantomJS 2.1.1
  • CasperJS 1.0.4 CasperJS 1.0.4
  • MacOSX 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 在casperjs 1.1.x beta和PhantomJS> 1.9.8中存在页面导航的一些问题,其中建议将PhantomJS降级到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? Github问题1485解决方案或@Ross解决方案可以解决问题 - 任何评论?

I also had this same enigmatic debug logging for my step: 我的步骤也有同样神秘的调试日志:

[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"

In my case I needed to click Submit button on an AJAX form that was a link element with href='javascript:;' 在我的情况下,我需要在AJAX表单上单击“提交”按钮,该表单是一个链接元素,其中包含href='javascript:;' . It turned out this in itself was not the main problem. 事实证明,这本身并不是主要问题。 Rather it was that their web system was built with Apache Wicket java web framework, which issues stateful sessions for each search interaction. 相反,他们的Web系统是使用Apache Wicket java Web框架构建的,该框架为每次搜索交互发出有状态会话。 And it happens via redirection – and this was the key point here. 它通过重定向发生 - 这是关键点。

Now CasperJS supports two engines PhantomJS and SlimerJS ... When digging into CasperJS documentation I wound this linked page Differences between SlimerJS and PhantomJS which states: 现在CasperJS支持两个引擎PhantomJSSlimerJS ...当深入研究CasperJS文档时,我创建了这个链接页面SlimerJS和PhantomJS之间的区别

'PhantomJS doesn't do redirections, whereas SlimerJS does.' “PhantomJS没有做重定向,而SlimerJS则没有。”

For reference here was my options as set to be most loose and with debug enabled (some of these are with the default values): 这里的参考是我的选项设置为最松散并启用了调试(其中一些是默认值):

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'
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM