javascript - 使用 fetch 比较 2 个页面的 HTML

标签 javascript node.js node-fetch

我正在尝试比较 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/

相关文章:

javascript - 网格的字段绑定(bind)。将新记录添加到 Store 后 View 仍然不一致

node.js - 如何在 Angular Universal 中使用 HTTP Node.js 请求

javascript - 将 async-await 与 node-fetch 结合使用不会将响应返回给调用方法

javascript - 如何将 CURL -F @filename 转换为nodejs

javascript - 访问深层嵌套图像

javascript - JQuery 移动版 : Vertically and horizontally center multiple images using grid

javascript - 每次单击按钮时 CSS 递增过渡动画

node.js - 我如何为多个集合做 Mongodb 聚合过滤器?

javascript - 如何创建一个发送消息的函数

node.js - 我看似有效的 URL 在本地解析,但在部署到 heroku 上时失败