GET 请求在 Postman 中有效,但在 NodeJS 中无效,使用请求包

问题描述

我一直在尝试使用 request-promise 包将一个简单的网页抓取脚本迁移到 NodeJS,但我总是收到以下错误作为输出

403 This IP has been automatically blocked

但是,如果我使用浏览器或 Postman 来触发请求,它可以完美运行(并且 IP 根本没有被阻止)

这是我用于 NodeJS 的代码

const request = require('request-promise');
const main = async () => {
    const options = {
        url: 'https://sfbay.craigslist.org/d/software-qa-dba-etc/search/sof',headers: {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/89.0.4389.90 Safari/537.36','Accept-Language':'en-US,en;q=0.5','Cache-Control': 'no-cache'
        }
    }
    try {
        const htmlResult = await request.get(options);
        console.log(htmlResult);
    } catch (e) {
        console.log(e);
    }

}

main();

我也试过 Axios,但输出是一样的。有什么想法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)