AirbnbSpider.py 文件源码

python
阅读 48 收藏 0 点赞 0 评论 0

项目:airbnb_scraper 作者: bashedev 项目源码 文件源码
def _last_page_number_in_search(response):
        """Get last page number of search results."""
        try:  # to get the last page number
            last_page = response.xpath('//ul[@data-id="SearchResultsPagination"]/li[last()-1]/a/div/text()').extract()
            return int(last_page[0])
        except IndexError:  # if there is no page number
            # get the reason from the page
            reason = response.xpath('//p[@class="text-lead"]/text()').extract()
            # and if it contains the key words set last page equal to 0
            if reason and ('find any results that matched your criteria' in reason[0]):
                logging.log(logging.DEBUG, 'No results on page' + response.url)
                return 0
            else:
                # otherwise we can conclude that the page
                # has results but that there is only one page.
                return 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号