【问题标题】:casperjs failed to access certain websites that even wget cancasperjs 无法访问甚至 wget 可以访问的某些网站
【发布时间】:2020-12-05 07:38:32
【问题描述】:

一个非常简单的示例链接https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm

即使没有任何头信息的wget也可以成功抓取信息。

但是,casperjs 只是不起作用

var casper=require("casper").create();
var mouse=require("mouse").create(casper);
var link="https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm";
casper.start().then(function() {
        this.open(link);
        this.wait(5000);  
});
casper.run(function(){
        this.echo(this.getPageContent()).exit();
});

总是输出

<html><head></head><body></body></html>

添加标题信息没有帮助,如下所示

this.open(link, {
                method: 'get',
                authority: 'www.accessdata.fda.gov',
                path: '/scripts/cder/daf/index.cfm',
                scheme: 'https',
                headers: {
                        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36',
                        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
                        'accept-encoding': 'gzip, deflate, br',
                        'accept-language': 'en-US,en;q=0.9,zh-TW;q=0.8,zh;q=0.7,zh-CN;q=0.6,ja;q=0.5',
                        'cache-control': 'max-age=0',
                        'sec-fetch-dest': 'document',
                        'sec-fetch-mode': 'navigate',
                        'sec-fetch-site': 'none',
                        'sec-fetch-user': '?1',
                        'upgrade-insecure-requests': '1'
                    
                }
        });

我尝试了许多标题样式的组合,但都不起作用。

然而,值得注意的是,上面的 casperjs 代码适用于某些网站,例如 http://docs.casperjs.org/en/latest/selectors.html

【问题讨论】:

    标签: web-scraping wget casperjs


    【解决方案1】:

    我刚刚注意到添加 --ssl-protocol=any

    casperjs --ssl-protocol=any yourScript.js
    

    解决了问题

    此链接有更多解释 CasperJS/PhantomJS doesn't load https page

    【讨论】:

      猜你喜欢
      • 2017-03-20
      • 2020-05-22
      • 1970-01-01
      • 2020-07-20
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-21
      相关资源
      最近更新 更多