我对一个问题感到绝望,我需要一些帮助...... 我使用node.js抓取网站列表,其中一些网站给了我这个错误,例如: http://www.fz-juelich.de/portal/DE/Home/home_node.html,解析错误,HPE_INVALID_HEADER_TOKEN
request.get({
url: uri,
timeout: timeout,
headers: {
referer: domain
}
}, (error, response, body) => {
if (error)
console.log(error);
console.log(body);
});
但是,curl -i --raw http://www.fz-juelich.de/portal/DE/Home/home_node.html 工作得很完美
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Cache-Control: no-cache
JSESSIONID=E594677A6CCA13BE0338E1D00A729C34; Path=/cae:
Content-Type: text/html;charset=utf-8
Content-Language: de
Set-Cookie: JSESSIONID=E594677A6CCA13BE0338E1D00A729C34; Path=/
Content-Length: 19677
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
此外,我可以在Chrome浏览器中看到此网站
我应该挖掘哪一方面以消除这些错误?
答案 0 :(得分:1)
我在属性中使用引号,这些引号对我来说是解决的:
request.post(url,{
headers: {
'Authorization': 'Basic onEnAGrosEncodedBase64',
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
'grant_type': 'client_credentials'
}
})
我希望可以帮助某人;)
答案 1 :(得分:0)
我结束这段旅程,我不再使用node.js进行抓取和解析
Go lang crawler在这里更合适,在http库中更加灵活,更容易编写真正的并发内容