【发布时间】:2020-07-12 01:36:32
【问题描述】:
我正在尝试比较 2 个 URL,它们应该是相同的,但是由于某种原因,我得到了一些差异。我想知道我是否对 NPM fetch 有一些基本的误解。
这是我的示例代码:
const fetch = require('node-fetch');
let startingPageBase = await fetch('https://www.example.com')
let startingPage = await startingPageBase.text()
let currentPageBase = await fetch('https://www.example.com')
let currentPage = await currentPageBase.text()
if (startingPageBase === currentPageBase) {
console.log('Checked ')
} else {
console.log('Not the same')
}
我基本上是在尝试检查 2 个页面的 HTML 是否相同。
【问题讨论】:
-
另外,不要忘记将您的
awaits 包装到异步函数中。你不能在异步函数之外使用await,但是你的浏览器控制台或IDE可能已经告诉你了。
标签: javascript node.js node-fetch