我使用节点获取和https-代理代理来使用代理发出请求,但是,只有当我发送agent时,我才从我要抓取的站点获得400个错误代码,没有它,一切都正常。
import fetch from 'node-fetch';
import Proxy from 'https-proxy-agent';
const ip = PROXIES[Math.floor(Math.random() * PROXIES.length)]; // PROXIES is a list of ips
const proxyAgent = Proxy(`http://${ip}`);
fetch(url, {
agent: proxyAgent,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.72 Safari/537.36'
}
}).then(res => res.text()).then(console.log)这导致400个错误代码,如下所示:

我完全不知道为什么会这样。如果你想复制这个问题,我正在刮https://azlyrics.com。请告诉我出了什么问题。
发布于 2022-06-05 13:54:42
这个问题已经解决了。我没有注意到我是用http代理向https站点提出请求的。该网站使用https协议,但代理仅限于http。更改为https代理是有效的。谢谢。
https://stackoverflow.com/questions/72501130
复制相似问题