我正在尝试比较 2 个网址,它们应该是相同的,但由于某种原因,我发现存在一些差异。我想知道我对 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')
}
我基本上是想检查两个页面的 HTML 是否相同。
最佳答案
您正在比较两个 promise ,而不是实际的文本值。
这样做:
if (startingPage === currentPage) {
console.log('Checked ')
} else {
console.log('Not the same')
}
关于javascript - 使用 fetch 比较 2 个页面的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60951644/