page.open() 函数对于某些 URL 不能正常工作

page.open() function doesn't work properly for some URLs

我是 node 新手。我已经使用 Node 和 Phantom 编写了一段代码来抓取网站。我的代码适用于 google.com 但不适用于 facebook,因为它在内部向其他文件发出 ajax 请求以获取数据。

var phantom = require('phantom');

phantom.create(function(ph) {
   return ph.createPage(function(page) {
       return page.open("https://facebook.com/", function(status) {
            if(status !== 'success'){
                console.log('Unable to load the url!');
                ph.exit();
            } else {
                setTimeout(function() {
                    return page.evaluate(function() {
                        return document.getElementsByTagName('body')[0].innerHTML;

                     }, function(result) {
                         console.log(result); //Log out the data.
                         ph.exit();
                     });
                }, 5000);
            };
        });
    });
});

所以基本上当我执行我的代码时,如果是 facebook,它会返回 unable to load,但如果是 google,它会返回 body 响应。

谁能告诉我应该做哪些更改才能得到结果?

PhantomJS 版本:1.9.0

您应该将一些命令行选项传递给 PhantomJS 以不使用 SSLv3 而仅使用 TLSv1 并可选择忽略 SSL 错误(--web-security=false 可能也有帮助):

phantom.create('--ssl-protocol=tlsv1', '--ignore-ssl-errors=true', function(ph) {
    ...

这可能是一个问题的原因是许多站点由于 Poodle 漏洞而删除了 SSLv3 支持。

This answer provides the solution for plain PhantomJS. My answer here 为 CasperJS 详细阐述了该问题。