Ejemplo n.º 1
0
    def parse_restaurant(self, response):
        # 緯度経度取得
        latitude, longitude = response.css(
            'img.js-map-lazyload::attr("data-original")').re(
                r'markers=.*?%7C([\d.]+),([\d.]+)')

        # address材料取得
        prefectures = response.css(
            'p.rstinfo-table__address span a::text').extract()
        street_number = response.css(
            'p.rstinfo-table__address span::text').extract()
        link = response.css('link[rel=canonical]').xpath(
            '@href').extract_first()

        # レビュー取得
        #mynameproject無いよと叱られる
        # try:
        #    print(link)
        #    res = subprocess.check_call('scrapy crawl tabelog_review -o review6.json -t json -a url=' + link)
        #except:
        #    print("Error.")

        item = Restaurant(
            name=response.css('.display-name').xpath(
                'string()').extract_first().strip(),
            address=''.join(prefectures + street_number),
            latitude=latitude,
            longitude=longitude,
            station=response.css(
                'dt:contains("最寄り駅")+dd span::text').extract_first(),
            score=response.css(
                'span.rdheader-rating__score-val-dtl::text').extract_first(),
        )

        yield item
Ejemplo n.º 2
0
    def parse_restaurant(self, response):
        """
        음식점 정보 페이지를 파싱합니다.
        """
        # 정보를 추출합니다.
        name = response.css("#pageheader h3")\
            .xpath("string()").extract_first().strip()
        address = response.css("dt:contains('주소') + dd")\
            .xpath("string()").extract_first().strip()
        phone = response.css("dt:contains('전화번호') + dd")\
            .xpath("string()").extract_first().strip()
        station = response.css("th:contains('지하철') + td")\
            .xpath("string()").extract_first().strip()

        # 위도 경도를 추출합니다.
        try:
            scripts = response.css("script:contains('var lat')").xpath(
                "string()").extract_first()
            latitude = re.findall(r"var lat = '(.+)'", scripts)[0]
            longitude = re.findall(r"var lng = '(.+)'", scripts)[0]
        except Exception as exception:
            print("예외 발생")
            print(exception)
            print()

        # 음식점 객체를 생성합니다.
        item = Restaurant(name=name,
                          address=address,
                          phone=phone,
                          latitude=latitude,
                          longitude=longitude,
                          station=station)
        yield item
Ejemplo n.º 3
0
    def parse_restaurant(self, response):
        # 緯度経度取得
        latitude, longitude = response.css(
            'img.js-map-lazyload::attr("data-original")').re(
                r'markers=.*?%7C([\d.]+),([\d.]+)')

        # address材料取得
        prefectures = response.css(
            'p.rstinfo-table__address span a::text').extract()
        street_number = response.css(
            'p.rstinfo-table__address span::text').extract()

        item = Restaurant(
            name=response.css('.display-name').xpath(
                'string()').extract_first().strip(),
            address=''.join(prefectures + street_number),
            latitude=latitude,
            longitude=longitude,
            station=response.css(
                'dt:contains("最寄り駅")+dd span::text').extract_first(),
            score=response.css(
                'span.rdheader-rating__score-val-dtl::text').extract_first(),
        )

        yield item
Ejemplo n.º 4
0
 def parse_restaurant(self, response):
     latitude, longitude = response.css(
         'img.js-map-lazyload::attr("data-original")').re(
             r'markers=.*?%7C([\d.]+),([\d.]+)')
     item = Restaurant(
         name=response.css('.display-name').xpath(
             'string()').extract_first().strip(),
         address=response.css('.rstinfo-table__address').xpath(
             'string()').extract_first().strip(),
         latitude=latitude,
         longitude=longitude,
         station=response.css(
             'dt:contains("最寄り駅")+dd span::text').extract_first(),
         score=response.css('#js-header-rating span::text').extract_first(),
     )
     yield item
Ejemplo n.º 5
0
    def parse_restaurant(self, response):
        latitude, longitude = response.css(
            'img.js-map-lazyload::attr("data-original")').re(
                r'markers=.*?%7C([\d.]+),([\d.]+)')

        item = Restaurant(
            name=response.css('.display-name').xpath(
                'string()').extract_first().strip(),
            address=response.css('[class="rstinfo-table__address"]').xpath(
                'string()').extract_first(),
            latitude=latitude,
            longitude=longitude,
            station=response.css('[class="linktree__parent-target-text"]'
                                 ).xpath('string()').extract_first(),
            score=response.css('[class="rdheader-rating__score-val-dtl"]').
            xpath('string()').extract_first(),
        )

        return item
Ejemplo n.º 6
0
    def parse_restaurant(self, response):
        """
        レストランの詳細ページをパースする。
        """
        # Google Static Mapsの画像のURLから緯度と経度を取得。
        latitude, longitude = response.css(
            'img.js-map-lazyload::attr("data-original")').re(
                r'markers=.*?%7C([\d.]+),([\d.]+)')

        # キーの値を指定してRestaurantオブジェクトを作成。
        item = Restaurant(
            name=response.css('.display-name').xpath('string()').extract_first().strip(),
            address=response.css('.rstinfo-table__address').xpath('string()').extract_first().strip(),
            latitude=latitude,
            longitude=longitude,
            station=response.css('dt:contains("最寄り駅")+dd span::text').extract_first(),
            score=response.css('.rdheader-rating__score-val-dtl::text').extract_first(),
        )

        yield item
Ejemplo n.º 7
0
    def parse_restaurant(self, response):
        """
        レストランの詳細ページをパースする
        """
        # Google Static Mapの画像のURLから緯度と経度を取得
        latitude, longitude = response.css(
            'img.js-map-lazyload::attr("data-original")').re(
                r'markers=.*?%7C([\d.]+),([\d.]+)')

        # キーの値を指定してRestaurantオブジェクトを作成
        item = Restaurant(
            name=response.css('.display-name').xpath(
                'string()').extract_first().strip(),
            address=response.css('[class="rstinfo-table__address"]').xpath(
                'string()').extract_first(),
            latitude=latitude,
            longitude=longitude,
            station=response.css(
                'dt:contains("最寄り駅")+dd span::text').extract_first(),
            score=response.css('[rel="v:rating"] span::text').extract_first(),
        )

        yield item  # Itemをyieldして、データを抽出する