如何判断网页是否被修改

发布于 2024-08-08 09:11:38 字数 148 浏览 12 评论 0原文

我有多个网页的快照,拍摄了两次。有什么可靠的方法来确定哪些网页已被修改?

我不能依赖像 RSS feed 这样的东西,而且我需要忽略像日期文本这样的小噪音。

理想情况下,我正在寻找 Python 解决方案,但直观的算法也很棒。

谢谢!

I have snapshots of multiple webpages taken at 2 times. What is a reliable method to determine which webpages have been modified?

I can't rely on something like an RSS feed, and I need to ignore minor noise like date text.

Ideally I am looking for a Python solution, but an intuitive algorithm would also be great.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

耀眼的星火 2024-08-15 09:11:39

只需使用 MD5 或 SHA1 拍摄文件快照...如果下次检查时值不同,则它们会被修改。

just take snapshots of the files with MD5 or SHA1...if the values differ the next time you check, then they are modified.

小清晰的声音 2024-08-15 09:11:38

好吧,首先您需要确定什么是噪音,什么不是。您可以使用 BeautifulSoup 之类的 HTML 解析器来消除噪音,漂亮地打印结果,然后将其作为字符串进行比较。

如果您正在寻找自动解决方案,可以使用 difflib.SequenceMatcher< /code>要计算页面之间的差异,请计算 相似度并将其与阈值进行比较。

Well, first you need to decide what is noise and what isn't. You can use a HTML parser like BeautifulSoup to remove the noise, pretty-print the result, and compare it as a string.

If you are looking for an automatic solution, you can use difflib.SequenceMatcher to calculate the differences between the pages, calculate the similarity and compare it to a threshold.

屌丝范 2024-08-15 09:11:38

解决方案实际上取决于您是否正在抓取特定网站,或者正在尝试创建一个适用于任何网站的程序。

您可以通过执行以下操作来查看哪些区域经常发生变化:

 diff <(curl http://stackoverflow.com/questions/) <(sleep 15; curl http://stackoverflow.com/questions/)

如果您只担心单个站点,则可以创建一些 sed 表达式来过滤掉时间戳等内容。您可以重复,直到小字段没有显示任何差异。

一般问题要困难得多,我建议初学者比较页面上的总字数。

The solution really depends if you are scraping a specific site, or are trying to create a program which will work for any site.

You can see which areas change frequently doing something like this:

 diff <(curl http://stackoverflow.com/questions/) <(sleep 15; curl http://stackoverflow.com/questions/)

If your only worried about a single site, you can create some sed expressions to filter out stuff like time stamps. You can repeat until no difference is shown for small fields.

The general problem is much harder, and I would suggest comparing the total word count on a page for starters.

傲世九天 2024-08-15 09:11:38

如果您将更改的阈值设置为以下距离,类似 Levenshtein Distance 的东西可能会派上用场忽略了适合您的适量噪音。

Something like Levenshtein Distance could come in handy if you set the threshold of the changes to a distance that ignored the right amount of noise for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文