lib/parse_each_page.rb
# process restaurants search result list page

process restaurants search result list page
process restaurants search result list page
def process_restaurants_search_result(doc, (prefecture, area1, area2), source_url, scraped_at)
      {
        list_count: doc.css(".c-page-count .c-page-count__num").last.text.strip.to_i,
        restaurants: doc.css(".list-rst").map { |entry|
          area_name, genre = entry.css(".list-rst__area-genre")[0].text.strip.split("/").map(&:strip)
          rating_str = entry.css(".list-rst__rating-val")[0]&.text&.strip || ""
          {
            restaurant_id: entry.attribute("data-rst-id").value,
            prefecture: prefecture,
            area1: area1,
            area2: area2,
            restaurant_url: entry.attribute("data-detail-url").value,
            name: entry.css("a.list-rst__rst-name-target")[0].text.strip,
            area_name: area_name,
            genre: genre,
            has_pr: entry.css(".list-rst__pr").any?,
            rating: rating_str,
            rating_int: rating_str_to_integer(rating_str),
            review_count: entry.css(".list-rst__rvw-count-num")[0].text.strip.to_i,
            dinner_budget: entry.css(".c-rating-v3__time--dinner+.c-rating-v3__val")[0].text.strip,
            lunch_budget: entry.css(".c-rating-v3__time--lunch+.c-rating-v3__val")[0].text.strip,
            has_holiday_notice: entry.css(".list-rst__holiday-notice").any?,
            search_words: entry.css("ul.list-rst__search-word li.list-rst__search-word-item").map(&:text).map(&:strip).join("|"),
            img_count: entry.css(".list-rst__rst-photo")[0].attribute("data-photo-set").value.split(",").select { |id_str| id_str.length > 0 }.length,
            has_calendar: entry.css(".list-rst__calendar").any?,
            source_url: source_url,
            scraped_at: scraped_at,
          }
        },
      }
    end
def process_restaurants_search_result ( doc , ( prefecture , area1 , area2 ) , source_url , scraped_at ) { list_count : doc . css ( ".c-page-count .c-page-count__num" ) . last . text . strip . to_i , restaurants : doc . css ( ".list-rst" ) . map { | entry | area_name , genre = entry . css ( ".list-rst__area-genre" ) [ 0 ] . text . strip . split ( "/" ) . map ( & :strip ) rating_str = entry . css ( ".list-rst__rating-val" ) [ 0 ] &. text &. strip || "" { restaurant_id : entry . attribute ( "data-rst-id" ) . value , prefecture : prefecture , area1 : area1 , area2 : area2 , restaurant_url : entry . attribute ( "data-detail-url" ) . value , name : entry . css ( "a.list-rst__rst-name-target" ) [ 0 ] . text . strip , area_name : area_name , genre : genre , has_pr : entry . css ( ".list-rst__pr" ) . any? , rating : rating_str , rating_int : rating_str_to_integer ( rating_str ) , review_count : entry . css ( ".list-rst__rvw-count-num" ) [ 0 ] . text . strip . to_i , dinner_budget : entry . css ( ".c-rating-v3__time--dinner+.c-rating-v3__val" ) [ 0 ] . text . strip , lunch_budget : entry . css ( ".c-rating-v3__time--lunch+.c-rating-v3__val" ) [ 0 ] . text . strip , has_holiday_notice : entry . css ( ".list-rst__holiday-notice" ) . any? , search_words : entry . css ( "ul.list-rst__search-word li.list-rst__search-word-item" ) . map ( & :text ) . map ( & :strip ) . join ( "|" ) , img_count : entry . css ( ".list-rst__rst-photo" ) [ 0 ] . attribute ( "data-photo-set" ) . value . split ( "," ) . select { | id_str | id_str . length > 0 } . length , has_calendar : entry . css ( ".list-rst__calendar" ) . any? , source_url : source_url , scraped_at : scraped_at , } } , } end
process restaurants search result list page
process restaurants search result list page
doc
<not_specific>
prefecture
<not_specific>
area1
<not_specific>
area2
<not_specific>
source_url
<not_specific>
scraped_at
<not_specific>