Sha256: 7b544d7a78807b14f473101582b5cb141b58f8013165528f2b5e42ba2648cfef

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

class SmartphoneFinder::Scraper
    DOMAIN="http://gsmarena.com/"


	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
	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
   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
   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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smartphone_finder-cli-1.0.7 lib/smartphone_finder/scraper.rb