lib/page_rankr/backlinks.rb in PageRankr-1.1.0 vs lib/page_rankr/backlinks.rb in PageRankr-1.2.0
- old
+ new
@@ -2,10 +2,12 @@
require 'cgi'
require 'nokogiri'
module PageRankr
class Backlinks
+ SEARCH_ENGINES = [:google, :bing, :yahoo, :altavista, :alltheweb, :alexa]
+
SEARCH_ENGINE_URLS = {
:google => "http://www.google.com/search?q=link%3A",
:bing => "http://www.bing.com/search?q=link%3A",
:yahoo => "http://siteexplorer.search.yahoo.com/search?p=",
:altavista => "http://www.altavista.com/web/results?q=link%3A",
@@ -21,9 +23,11 @@
:alltheweb => "//span[@class='ofSoMany']/text()",
:alexa => "//linksin/@num"
}
def self.lookup(site, *search_engines)
+ search_engines = SEARCH_ENGINES if search_engines.empty?
+
backlinks = {}
search_engines.each do |engine|
next unless SEARCH_ENGINE_URLS[engine]
doc = Nokogiri::HTML(open(SEARCH_ENGINE_URLS[engine] + CGI.escape(site)))
count = doc.at(SEARCH_EGNINE_PATHS[engine]).to_s