【问题标题】:Casperjs does not redirect if there is a 'let' in javascript如果 javascript 中有“let”,Casperjs 不会重定向
【发布时间】:2019-09-27 03:56:38
【问题描述】:

例如这是一个 html 页面的来源:example.html

<html>
<head></head>
<body>
    <script>
    for (let i = 0; i < 10; ++i) {

    }
    window.location = 'http://example.com';
    </script>
</body>
</html>

执行命令以casperjs打开example.html页面

casper.start('example.html')

我没想到的结果。 casperjs 无法重定向到 http://example.com

但如果我通过替换for 来编辑上面的example.html 页面

let i = 0 ~~> var i = 0

一切都为我解决了。 casperjs 将被重定向到 http://example.com

如何解决每个网站的这种情况?

【问题讨论】:

    标签: phantomjs casperjs


    【解决方案1】:

    CasperJS 基于 PhantomJS,它在 Javascript 功能方面非常过时,根本不支持 ES6(let 是 ES6 的一个特性),绝对不可能 polyfill 关键字。

    由于 PhantomJS is suspended 强烈建议转移到另一个工具。我建议puppeteer,它正在由 Google 积极开发并且有很好的community support

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多