首页 > 解决方案 > 为什么 node-fetch 在此站点上不起作用?

问题描述

我正在尝试抓取网站https://shmoti.com。但不幸的是,node-fetch 的fetch方法根本没有得到响应。它适用于其他网站。

这是我的代码

const fetch = require("node-fetch")
fetch('https://shmoti.com', options = {headers : {'User-Agent' : 'Mozilla/5.0'}}).then(res=>res.text()).then(res=>console.log(res)) 

解决响应对象的第一个承诺一直处于挂起状态。

我什至尝试过拥有一个 User-Agent 。我设置了 60 秒的超时时间。scrapy我可以使用python 中的库成功抓取该站点,但使用fetch方法,它总是超时。

为什么会这样?我怎样才能解决这个问题 ?

我也可以 ping 该网站并在我的浏览器中打开它,但只有从节点获取不起作用。

标签: javascriptnode.jsfetch

解决方案


推荐阅读