Class: PageRankr::Backlinks

Inherits:
Object
  • Object
show all
Defined in:
lib/page_rankr/backlinks.rb

Constant Summary collapse

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",
  :alltheweb => "http://www.alltheweb.com/search?q=link%3A",
  :alexa     => "http://data.alexa.com/data?cli=10&dat=snbamz&url="
}
SEARCH_EGNINE_PATHS =
{
  :google    => "//p[@id='resultStats']/b[3]/text()",
  :bing      => "//span[@class='sb_count']/text()",
  :yahoo     => "//ol[@id='results-tab']/li[2]/a/text()",
  :altavista => "//a[@class='lbl']/text()",
  :alltheweb => "//span[@class='ofSoMany']/text()",
  :alexa     => "//linksin/@num"
}

Class Method Summary collapse

Class Method Details

.lookup(site, *search_engines) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/page_rankr/backlinks.rb', line 25

def self.lookup(site, *search_engines)
  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
    count = count.gsub('1-10', '').gsub(/[a-zA-Z,\s\(\)]/, '')
    backlinks[engine] = count.to_i
  end
  backlinks
end