【发布时间】:2021-06-13 12:28:18
【问题描述】:
所以我抓取一个网络,我需要使用特定的 cookie,但我不知道如何准确地使用“获取”
const url="https://www.example.com";
let response = await fetch(url),
html = await response.text();
let $ = cheerio.load(html)
var example= $('.exampleclass').text();
现在我可以抓取网络,但如果我不得不使用特定的 cookie,我不知道如何将其放入 fetch。
在 python 中是这样的
response = requests.get(url, headers=headers, cookies=cookies)
谢谢!
【问题讨论】:
-
您使用的是哪个模块? node-fetch?
-
可以参考这个this previous post
-
@Muhammad.fatiu 这个问题是关于浏览器内获取的; OP 的问题是关于节点的。
-
无论如何,要设置 cookie,您需要添加 Cookie header:
await fetch(url, { headers: { "Cookie": "a=b" }})之类的东西应该这样做。 -
仅供参考,它是 scrape 和 scraping 不是废品和报废
标签: javascript node.js web