lib/page_rankr/backlinks/google.rb in PageRankr-1.4.3 vs lib/page_rankr/backlinks/google.rb in PageRankr-1.5.0
- old
+ new
@@ -1,15 +1,19 @@
require 'cgi'
+require 'json'
module PageRankr
class Backlinks < Tracker
class Google < Backlink
- def url(site)
- "http://www.google.com/search?q=link%3A%22#{CGI.escape(site)}%22"
+
+ # overloaded to use Google's AJAX search API
+ # http://code.google.com/apis/ajaxsearch/documentation/
+ def initialize(site)
+ @backlinks = clean JSON.parse( open( url(site)).read )["responseData"]["cursor"]["estimatedResultCount"].to_s
end
- def xpath
- "//div[@id='resultStats']/text()"
+ def url(site)
+ "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q=link%3A#{CGI.escape(site)}"
end
end
end
end
\ No newline at end of file