views:

273

answers:

4

hello,

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!

+1  A: 

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.

Alex Sexton
Levenshtein distance is O(n^2) and will most likely be much to inefficient for whole webpages. You can however generalize it to sequences and perceive words as symbols instead of characters. That might work.
bayer
+7  A: 

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.

Lukáš Lalinský
+2  A: 

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.

brianegge
yeah I am looking for a general approach. Total word count is an interesting (and straightforward) idea.
Plumo
A: 

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

ghostdog74
the problem is that kind of approach can't deal with noise. For instance a webpage may display today's date, which will change even when the content was not modified.
Plumo
ic.. i misunderstood your requirement.
ghostdog74