zahar
zahar

Reputation: 33

Detect if remote page changed

I need to detect if a remote page changed. I wrote:

a = JSON.parse open('http://en.wikipedia.org/wiki/Main_Page').read
b = JSON.parse open('http://en.wikipedia.org/wiki/Main_Page').read

The page was not changed, but a == b returned false. Is it possible to detect if the page changed or not?

Upvotes: 1

Views: 236

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121010

What have you put JSON.parse there for?? Do you expect the wikipedia mainpage to be json-encoded?

require 'open-uri'
a = open('http://en.wikipedia.org/wiki/Main_Page').read
b = open('http://en.wikipedia.org/wiki/Main_Page').read
puts a == b
# ⇒ true

Whether you have the dynamically created pages (produced by CMS or likewise), you need to examine the web page content and explicitly cast the page to, say, canonical view: cut all the temporary information off and compare the static parts only.

Upvotes: 1

Related Questions