[英]casperjs failed to access certain websites that even wget can
一個非常簡單的示例鏈接https://www.accessdata.fda.gov/scripts/cder/daf/index.cfm 。
即使 wget 沒有任何 header 信息,也可以成功抓取信息。
但是,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();
});
它總是 output
<html><head></head><body></body></html>
添加 header 信息沒有幫助,如下所示
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'
}
});
我嘗試了許多 header 風格的組合,但都不起作用。
但是,值得注意的是,上面的 casperjs 代碼適用於某些網站,例如http://docs.casperjs.org/en/latest/selectors.html
我剛剛注意到添加 --ssl-protocol=any
casperjs --ssl-protocol=any yourScript.js
解決了這個問題
此鏈接有更多解釋CasperJS/PhantomJS 不加載 https 頁面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.