class SmartphoneFinder::Scraper

Constants

DOMAIN

Public Class Methods

get_brands() click to toggle source
# File lib/smartphone_finder/scraper.rb, line 5
def self.get_brands
  html= open(DOMAIN)
  scrapped=Nokogiri::HTML(html)        
  scrapped.css(".brandmenu-v2 ul li a").each do |e|

          SmartphoneFinder::Brand.new(e.text ,e.attribute("href").value)

  end
end
get_by_keyword(keyword) click to toggle source
# File lib/smartphone_finder/scraper.rb, line 37
def self.get_by_keyword(keyword)
      self.get_brands
      search_results=[]
      html =  open(DOMAIN+"results.php3?sQuickSearch=yes&sName="+keyword)
      scrapped = Nokogiri::HTML(html)
      scrapped.css("div.makers ul a").each do |a|
         device_name_no_php=a.attribute("href").value.split("-")
         device_name_collector=device_name_no_php[0].split("_");
         brand=SmartphoneFinder::Brand.find_by_name(device_name_collector[0])
         device_name_collector.shift
         device_name=device_name_collector.join(" ")
         device=SmartphoneFinder::Device.new(device_name,a.attribute("href").value,brand)
         brand.add_device(device)
         search_results.push(brand.name + ": " +device_name)
      end
      search_results
end
get_device_spec(device) click to toggle source
# File lib/smartphone_finder/scraper.rb, line 23
def self.get_device_spec(device)
       spec_table=""
       url=device.url
       html= open(DOMAIN+url)
       scrapped=Nokogiri::HTML(html)        
       scrapped.css("#specs-list table").each do |table|
            spec_table=spec_table + table.css("th").text + ":\n"
            table.css("tr").each do |tr|
                    spec_table=spec_table + "  " + tr.css(".ttl a").text + " - " + tr.css(".nfo").text + "\n"
            end
         spec_table=spec_table + "--------------------------------------------------------------\n"
     end
 device.specifications= SmartphoneFinder::Specifications.new(device,spec_table)
end
get_devices_by_brand(brand) click to toggle source
# File lib/smartphone_finder/scraper.rb, line 14
  def self.get_devices_by_brand(brand)
          url=brand.url
    html= open(DOMAIN+url)
    scrapped=Nokogiri::HTML(html)        
    scrapped.css(".makers ul li a").each do |a|
    device=SmartphoneFinder::Device.new(a.css("span").text,a.attribute("href").value,brand)
brand.add_device(device)
    end
  end