Class: SmartphoneFinder::Scraper
- Inherits:
-
Object
- Object
- SmartphoneFinder::Scraper
- Defined in:
- lib/smartphone_finder/scraper.rb
Constant Summary collapse
- DOMAIN =
"http://gsmarena.com/"
Class Method Summary collapse
- .get_brands ⇒ Object
- .get_by_keyword(keyword) ⇒ Object
- .get_device_spec(device) ⇒ Object
- .get_devices_by_brand(brand) ⇒ Object
Class Method Details
.get_brands ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/smartphone_finder/scraper.rb', line 6 def self.get_brands html= URI.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) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/smartphone_finder/scraper.rb', line 38 def self.get_by_keyword(keyword) self.get_brands search_results=[] html = URI.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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/smartphone_finder/scraper.rb', line 24 def self.get_device_spec(device) spec_table="" url=device.url html= URI.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) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/smartphone_finder/scraper.rb', line 15 def self.get_devices_by_brand(brand) url=brand.url html= URI.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 |