![](/img/trans.png)
[英]How to extract status code of a protected web page with Node.js backend?
[英]400 status code when using Node.js to hit a specific web page. And a 200 status code when hitting same web page from my browser. What gives?
有问题的网址: https : //www.theroyalamerican.com/schedule
我正在构建一个 node.js 脚本来使用request-promise
包(它为我抓取页面的 html)抓取上面的网页。 不幸的是,当我运行我的代码时,它给了我来自 Squarespace(该站点的明显主机)的400 状态代码。
奇怪的是,当我在 Web 浏览器中浏览到相同的 URL 时,我可以毫无问题地将其拉起 - 200 status code 。
我没有这个问题,我的节点脚本和网络浏览器似乎与任何其他网页不匹配。 很好奇这里发生了什么......
const rp = require('request-promise');
const $ = require('cheerio');
const url = 'https://www.theroyalamerican.com/schedule';
rp(url)
.then(function(html) {
console.log(html);
})
.catch(function(err) {
console.log(err);
//handle error
});
检查在浏览器和 Node.js 中请求此页面时发送的所有标头。 可能某些标头会影响可能的响应(例如Content-Type
可能?或者尝试传递Origin
标头)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.