Dougui
Dougui

Reputation: 7230

Check if two urls are for the same website

I'm looking for a way to compare two urls. I can do:

URI('http://www.test.com/blabla').host

to have the base name, but this not reliable. For example:

URI('http://www.test.com/blabla').host == URI('http://test.com/blabla').host

returns false, but they can be the same site. To have the IP address is not reliable too because if I do:

IPSocket.getaddress(URI('http://hello.herokuapp.com').host) ==
IPSocket.getaddress(URI('http://test.herokuapp.com').host)

It returns true, but they are not the same site. Is there a more reliable way?

Upvotes: 0

Views: 2859

Answers (1)

astropanic
astropanic

Reputation: 10939

The site under http://foo.com can be the same as under http://www.foo.com, but it can be a totally different site, due to web server configuration. It depends on the DNS config too, which IP points to www and which one to without www.

If you want compare two sites, you need to fetch the content, and compare key parts (using nokogiri for example) about similarities.

Nowadays due to sidebars and news, two consequent request to the same url, gives slight different html responses.

Upvotes: 4

Related Questions