automation - 无法使用 Slimerjs、casperjs、phantomjs 打开 https 网页

标签 automation phantomjs casperjs slimerjs

这是我第一次无法使用 headless 浏览器打开网站,例如: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();

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

我有什么想念的吗?

最佳答案

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

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

所以它不是页面不加载。是保护机制根据 PhantomJS 实现的检查检测到 PhantomJS 是机器人

Page Loaded

最简单的修复方法是使用 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 下不起作用的网站上浪费时间

更新 1

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

Cookies

关于automation - 无法使用 Slimerjs、casperjs、phantomjs 打开 https 网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49839595/

相关文章:

testing - 带有 Electron 的 TestCafe : Determine if app is visible on Windows desktop

ruby - 部署到 heroku 的 Watir 应用程序

javascript - 如何访问并点击 PhantomJS 按钮

python - 在使用 Python 启动的脚本中运行 phantomjs/casperjs native 选项

Azure 自动化记录到 Application Insight

php - 是否可以使用这种结构运行 MySQL 请求?

javascript - 自定义函数的 ruby​​execute_script 导致没有结果

parsing - CasperJS:如何设置代理,以便Google Analytics(分析)将忽略它

javascript - Phantomjs/Casper 不会在 &lt;iframe&gt; 内渲染 <embed>

javascript - 如何检查几个元素之一是否存在?