这是我第一次无法使用 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 是机器人
最简单的修复方法是使用 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,但仍然无法正常工作。这意味着有一些硬检查
关于automation - 无法使用 Slimerjs、casperjs、phantomjs 打开 https 网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49839595/