【问题标题】:Cant open https web using Slimerjs, casperjs, phantomjs无法使用 Slimerjs、casperjs、phantomjs 打开 https 网页
【发布时间】:2018-04-15 07:43:46
【问题描述】:

这是我第一次无法使用无头浏览器打开网站,例如:phantomjs、slimerjs 或 casperjs。我只想打开网站。我只是创建了非常基本的脚本来打开网站并截取屏幕截图。但是其中 3(三)张给了我空白图片。

我尝试使用:

--debug=true 
--ssl-protocol=TLSv1.2 (i try each of available protocol) 
--ignore-ssl-errors=true

这是我的脚本:

Slimerjs

var page = require("webpage").create();
page.open("https://domain/")
    .then(function(status){
         if (status == "success") {
            page.viewportSize = { width:1024, height:768 };
            page.render('screenshot.png');
         }
         else {
             console.log("Sorry, the page is not loaded");
         }
         page.close();
         phantom.exit();
    });

phantomjs

var page = require('webpage').create();
page.open('https://domain/', function() {
  page.render('screenshot.png');
  phantom.exit();
});

casperjs

var casper = require('casper').create({
  viewportSize: {width: 950, height: 950}
});

casper.start('https://domain/', function() {
    this.capture('screenshot.png');
});

casper.run();

我什至尝试使用屏幕截图服务来了解它们是否可以打开。但他们都没有给我任何东西。

我有什么想念的吗?

【问题讨论】:

    标签: automation phantomjs casperjs slimerjs


    【解决方案1】:

    问题不是因为 PhantomJS 本身。您正在检查的网站受到F5 network protection

    的保护

    https://devcentral.f5.com/articles/these-are-not-the-scrapes-youre-looking-for-session-anomalies

    所以不是页面没有加载。是保护机制检测到 PhantomJS 是基于他们已实施的检查的机器人

    最简单的修复方法是使用 Chrome 而不是 PhantomJS。否则这意味着相当长的调查时间

    过去一些类似的未回答/回答的问题

    Selenium and PhantomJS : webpage thinks Javascript is disabled

    PhantomJS get no real content running on AWS EC2 CentOS 6

    file_get_contents while bypassing javascript detection

    Python POST Request Not Returning HTML, Requesting JavaScript Be Enabled

    我会用我找到的更多细节更新这篇文章。但我的经验表明,选择有效的方法,而不是在 PhantomJS 下无效的网站上浪费时间

    Update-1

    我已尝试将浏览器 cookie 导入 PhantomJS,但仍然无法正常工作。这意味着有一些严格的检查

    【讨论】:

    • 你真的给了我线索。我会试试。顺便提一句。你说的铬是什么意思。你的意思是puppeteer
    • 您可以根据需要使用它或 Selenium + Chrome。 Selenium 在几乎所有语言中都有绑定
    • 很高兴为此信息花费了很多声誉。真的很值得。谢谢兄弟
    【解决方案2】:

    我在使用 phantomJS 时遇到了这个问题,以下服务参数解决了这个问题:

    --ignore-ssl-errors=true
    --ssl-protocol=any
    --web-security=false
    --proxy-type=None
    

    在 casperJS 和 slimerJS 方面无法为您提供帮助,也不知道为什么会这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-02
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多