class Scrap

Public Class Methods

start_nokogiri(city_name) click to toggle source
# File lib/hotels_in_iraq/scraper.rb, line 2
def self.start_nokogiri(city_name)
 Hotel.clear_all
 City.clear_all
 if city_name == "Erbil"
   html=open("http://www.booking.com/searchresults.html?aid=7344259;label=metatripad-link-dmetanar-hotel-572255_xqdz-2160b895b20379275615da7ce1accb60_los-01_bw-052_dom-com_curr-IQD_gst-02_nrm-01_clkid-WInfXgoQIW8AAHE2vB0AAABG_aud-0000_mbl-M_pd-B_sc-2;sid=ab45cb9c3d61edaab36a87657e4bd130;checkin=2017-03-19;checkout=2017-03-20;dest_id=-3106433;dest_type=city;highlighted_hotels=572255;hlrd=12;keep_landing=1;redirected=1;source=hotel&utm_campaign=nar&utm_content=los-01_bw-052_dom-com&utm_medium=dmeta&utm_source=metatripad&utm_term=hotel-572255&")
 elsif city_name=="Baghdad"
   html=open("http://www.booking.com/searchresults.en-gb.html?aid=7344259;label=metatripad-link-dmetanar-hotel-572255_xqdz-2160b895b20379275615da7ce1accb60_los-01_bw-052_dom-com_curr-IQD_gst-02_nrm-01_clkid-WInfXgoQIW8AAHE2vB0AAABG_aud-0000_mbl-M_pd-B_sc-2;sid=ab45cb9c3d61edaab36a87657e4bd130;checkin_month=3;checkin_monthday=19;checkin_year=2017;checkout_month=3;checkout_monthday=20;checkout_year=2017;city=-3106433;class_interval=1;dest_id=-3103581;dest_type=city;group_adults=2;group_children=0;highlighted_hotels=805888;hlrd=0;label_click=undef;no_rooms=1;offset=0;qrhpp=49f276a70adc52941d2535c7fc06a945-hotel-0;room1=A%2CA;sb_price_type=total;search_pageview_id=290649fe9fd0018f;search_selected=0;src=searchresults;src_elem=sb;ss=Baghdad;ss_raw=Baghdad;ssb=empty;srpos=5;origin=search")
 elsif city_name=="Karbala"
   html=open("http://www.booking.com/searchresults.html?aid=376363&label=booking-name-MAwwjickQVoQNs4vmbOhyQS36078172878%3Apl%3Ata%3Ap1%3Ap21%2C157%2C000%3Aac%3Aap1t1%3Aneg%3Afi%3Atiaud-146342138710%3Akwd-65526620%3Alp9069852%3Ali%3Adec%3Adm&sid=db1ae9e1a86660609634c6008584343e&sb=1&src=searchresults&src_elem=sb&error_url=http%3A%2F%2Fwww.booking.com%2Fsearchresults.html%3Faid%3D376363%3Blabel%3Dbooking-name-MAwwjickQVoQNs4vmbOhyQS36078172878%253Apl%253Ata%253Ap1%253Ap21%252C157%252C000%253Aac%253Aap1t1%253Aneg%253Afi%253Atiaud-146342138710%253Akwd-65526620%253Alp9069852%253Ali%253Adec%253Adm%3Bsid%3Ddb1ae9e1a86660609634c6008584343e%3Bcheckin_month%3D3%3Bcheckin_monthday%3D16%3Bcheckin_year%3D2017%3Bcheckout_month%3D3%3Bcheckout_monthday%3D26%3Bcheckout_year%3D2017%3Bclass_interval%3D1%3Bdest_id%3D101%3Bdest_type%3Dcountry%3Bdtdisc%3D0%3Bgroup_adults%3D2%3Bgroup_children%3D0%3Bhlrd%3D0%3Bhyb_red%3D0%3Binac%3D0%3Blabel_click%3Dundef%3Bmcs%3D0%3Bmih%3D0%3Bnha_red%3D0%3Bno_rooms%3D1%3Boffset%3D0%3Bpostcard%3D0%3Braw_dest_type%3Dcountry%3Bredirected_from_city%3D0%3Bredirected_from_landmark%3D0%3Bredirected_from_region%3D0%3Broom1%3DA%252CA%3Bsb_price_type%3Dtotal%3Bsearch_selected%3D1%3Bsrc%3Dindex%3Bsrc_elem%3Dsb%3Bss%3DIraq%3Bss_all%3D0%3Bss_raw%3Diraq%3Bssb%3Dempty%3Bsshis%3D0%26%3B&ss=Karbala%2C+Iraq&ssne=Iraq&ssne_untouched=Iraq&checkin_month=3&checkin_monthday=16&checkin_year=2017&checkout_month=3&checkout_monthday=26&checkout_year=2017&room1=A%2CA&no_rooms=1&group_adults=2&group_children=0&ss_raw=Iraq+k&ac_position=0&ac_langcode=en&dest_id=-3107076&dest_type=city&search_pageview_id=15b18f124645014c&search_selected=true&search_pageview_id=15b18f124645014c&ac_suggestion_list_length=5&ac_suggestion_theme_list_length=0&track_sssu=1")
 elsif city_name=="An Najaf"
    html=open("http://www.booking.com/searchresults.html?aid=376363&label=booking-name-MAwwjickQVoQNs4vmbOhyQS36078172878%3Apl%3Ata%3Ap1%3Ap21%2C157%2C000%3Aac%3Aap1t1%3Aneg%3Afi%3Atiaud-146342138710%3Akwd-65526620%3Alp9069852%3Ali%3Adec%3Adm&sid=db1ae9e1a86660609634c6008584343e&sb=1&src=searchresults&src_elem=sb&error_url=http%3A%2F%2Fwww.booking.com%2Fsearchresults.html%3Faid%3D376363%3Blabel%3Dbooking-name-MAwwjickQVoQNs4vmbOhyQS36078172878%253Apl%253Ata%253Ap1%253Ap21%252C157%252C000%253Aac%253Aap1t1%253Aneg%253Afi%253Atiaud-146342138710%253Akwd-65526620%253Alp9069852%253Ali%253Adec%253Adm%3Bsid%3Ddb1ae9e1a86660609634c6008584343e%3Bcheckin_month%3D3%3Bcheckin_monthday%3D16%3Bcheckin_year%3D2017%3Bcheckout_month%3D3%3Bcheckout_monthday%3D26%3Bcheckout_year%3D2017%3Bclass_interval%3D1%3Bdest_id%3D-3107076%3Bdest_type%3Dcity%3Bdtdisc%3D0%3Bgroup_adults%3D2%3Bgroup_children%3D0%3Bhlrd%3D0%3Bhyb_red%3D0%3Binac%3D0%3Blabel_click%3Dundef%3Bmcs%3D0%3Bmih%3D0%3Bnha_red%3D0%3Bno_rooms%3D1%3Boffset%3D0%3Bpostcard%3D0%3Braw_dest_type%3Dcity%3Bredirected_from_city%3D0%3Bredirected_from_landmark%3D0%3Bredirected_from_region%3D0%3Broom1%3DA%252CA%3Bsb_price_type%3Dtotal%3Bsearch_selected%3D1%3Bsrc%3Dsearchresults%3Bsrc_elem%3Dsb%3Bss%3DKarbala%252C%2520Iraq%3Bss_all%3D0%3Bss_raw%3DIraq%2520k%3Bssb%3Dempty%3Bsshis%3D0%3Bssne_untouched%3DIraq%26%3B&ss=An+Najaf%2C+Iraq&ssne=Karbala&ssne_untouched=Karbala&city=-3107076&checkin_month=3&checkin_monthday=16&checkin_year=2017&checkout_month=3&checkout_monthday=26&checkout_year=2017&room1=A%2CA&no_rooms=1&group_adults=2&group_children=0&ss_raw=Iraq+n&ac_position=0&ac_langcode=en&dest_id=-3102873&dest_type=city&search_pageview_id=52918f2d938b013f&search_selected=true&search_pageview_id=52918f2d938b013f&ac_suggestion_list_length=5&ac_suggestion_theme_list_length=0&track_sssu=1")
 else
   html=open("http://www.booking.com/searchresults.html?aid=376363&label=booking-name-MAwwjickQVoQNs4vmbOhyQS36078172878%3Apl%3Ata%3Ap1%3Ap21%2C157%2C000%3Aac%3Aap1t1%3Aneg%3Afi%3Atiaud-146342138710%3Akwd-65526620%3Alp9069852%3Ali%3Adec%3Adm&sid=db1ae9e1a86660609634c6008584343e&sb=1&src=searchresults&src_elem=sb&error_url=http%3A%2F%2Fwww.booking.com%2Fsearchresults.html%3Faid%3D376363%3Blabel%3Dbooking-name-MAwwjickQVoQNs4vmbOhyQS36078172878%253Apl%253Ata%253Ap1%253Ap21%252C157%252C000%253Aac%253Aap1t1%253Aneg%253Afi%253Atiaud-146342138710%253Akwd-65526620%253Alp9069852%253Ali%253Adec%253Adm%3Bsid%3Ddb1ae9e1a86660609634c6008584343e%3Bcheckin_month%3D3%3Bcheckin_monthday%3D16%3Bcheckin_year%3D2017%3Bcheckout_month%3D3%3Bcheckout_monthday%3D26%3Bcheckout_year%3D2017%3Bcity%3D-3107076%3Bclass_interval%3D1%3Bdest_id%3D-3102873%3Bdest_type%3Dcity%3Bdtdisc%3D0%3Bgroup_adults%3D2%3Bgroup_children%3D0%3Bhlrd%3D0%3Bhyb_red%3D0%3Binac%3D0%3Blabel_click%3Dundef%3Bmcs%3D0%3Bmih%3D0%3Bnha_red%3D0%3Bno_rooms%3D1%3Boffset%3D0%3Bpostcard%3D0%3Braw_dest_type%3Dcity%3Bredirected_from_city%3D0%3Bredirected_from_landmark%3D0%3Bredirected_from_region%3D0%3Broom1%3DA%252CA%3Bsb_price_type%3Dtotal%3Bsearch_selected%3D1%3Bsrc%3Dsearchresults%3Bsrc_elem%3Dsb%3Bss%3DAn%2520Najaf%252C%2520Iraq%3Bss_all%3D0%3Bss_raw%3DIraq%2520n%3Bssb%3Dempty%3Bsshis%3D0%3Bssne_untouched%3DKarbala%26%3B&ss=Duhok%2C+Iraq&ssne=An+Najaf&ssne_untouched=An+Najaf&city=-3102873&checkin_month=3&checkin_monthday=16&checkin_year=2017&checkout_month=3&checkout_monthday=26&checkout_year=2017&room1=A%2CA&no_rooms=1&group_adults=2&group_children=0&ss_raw=Iraq+D&ac_position=0&ac_langcode=en&dest_id=-3104831&dest_type=city&search_pageview_id=bd049063a7da01bc&search_selected=true&search_pageview_id=bd049063a7da01bc&ac_suggestion_list_length=5&ac_suggestion_theme_list_length=0&track_sssu=1")
 end
 doc=Nokogiri::HTML(html)
# doc.css("div#search_results_table")
 doc.css("div#hotellist_inner").children.each do |element|
 hotel_name = element.css("span.sr-hotel__name").text.strip.gsub("\n",'')
 city_name = element.css("div.address").text.strip.gsub("\n",'')
 hotel_describe = element.css("table td p.hotel_desc").text.strip.gsub("\n",'')
 hotel_booking = element.css("span.lastbooking").text.strip.gsub("\n",'')
 hotel_rating = element.css("span.js--hp-scorecard-scoreword").text.strip.gsub("\n",'')
 if hotel_name != ""
   city = City.new(city_name)
   hotel = Hotel.new(hotel_name,city,hotel_rating,hotel_describe,hotel_booking)

 end
 end
 end