Извлеките все нумерацию ссылок на страницы с scrapy для url = https://www.blablacar.in/ride-sharing/new-delhi/chandigarh/ - PullRequest
0 голосов
/ 12 июня 2018

Может кто-нибудь, пожалуйста, помогите мне Извлечь все пагинационные ссылки на страницы с scrapy для url=https://www.blablacar.in/ride-sharing/new-delhi/chandigarh/

КАК я уже попробовал с python, но не выбирая детали

мой код выглядит следующим образом=====================

allowed_domains = ['blablacar.in']
    start_urls = ['https://www.blablacar.in/ride-sharing/new-delhi/chandigarh/']

    def parse(self, response):
        products = response.css('.trip-search-results li')
        for p in products:
            brand = p.css('.ProfileCard-info--name::text').extract_first().strip()
            price = p.css('.description .time::attr(content)').extract_first()
            item = ProductItem()
            item['brand'] = brand
            item['price'] = price
            yield item
        nextPageLinkSelector = response.css('.js-trip-search-pagination::attr(href)').extract_first()
        if nextPageLinkSelector:
            nextPageLink = nextPageLinkSelector
            yield scrapy.Request(url=response.urljoin(nextPageLink), )

Ответы [ 2 ]

0 голосов
/ 12 июня 2018

Попробуйте перейти по ссылкам следующей страницы:

nextPageLink = response.xpath("//*[@class='pagination']//*[@class='next' and not(contains(@class,'disabled'))]/a/@href").extract_first()
if nextPageLink:
    yield response.follow(nextPageLink,callback=self.parse)
0 голосов
/ 12 июня 2018

Вам просто нужно найти ссылку на следующую страницу и перейти по ней:

def parse(self, response):
    products = response.css('.trip-search-results li')
    for p in products:
        brand = p.css('.ProfileCard-info--name::text').extract_first().strip()
        price = p.css('.description .time::attr(content)').extract_first()
        item = ProductItem()
        item['brand'] = brand
        item['price'] = price
        yield item

    # Here is the pagination following.
    for a_tag in response.css('.pagination .next:not(.disabled) a'):
        yield response.follow(a_tag, self.parse_route)
...