Scrapy url итерационный метр - PullRequest
0 голосов
/ 28 октября 2019

У меня проблема с итератором. Я создал паука с копией, URL-адрес паука - "www.url.com/id?=1" Мне нужна итерация в URL для других страниц "www.url.com/ id? = 2 "" www.url.com/id?=3 "... Я пытаюсь создать счетчик внутри класса

class MercadoSpider(CrawlSpider):
contador=1
name = 'mercado'
item_count = 0
allowed_domain = ['https://www.qdq.com/']


start_urls = ['https://www.qdq.com/search?location=Ver%20resultados%20en%20toda%20España&query=imprentas&ine_code=&kind=N&page='+str(contador)
    ]

contador+1
rules = {
    # Para cada item
    Rule(LinkExtractor(allow = (), restrict_xpaths = ('/html/body/div[1]/div/div/div[1]/main/div/div/div/div[2]/div[3]/ul/li[8]/@href'))),
    Rule(LinkExtractor(allow =(), restrict_xpaths = ('//a[@class="business-card-link"]')),
                        callback = 'parse_item', follow = False)
}
def parse_item(self, response):

    ml_item = MercadoItem()
    #info de producto
    ml_item['nombre'] = response.xpath('//h1[@class="title"]/text()').extract()
    ml_item['web'] = response.xpath('/html/body/div[1]/div/div/div[1]/main/div/div[1]/div[2]/div[1]/div/div[4]/a/@href').extract()
    data = response.xpath('/html/head/script[3]/text()').extract()
    phone_number = re.search(r'"telephone":"(.*?)","address"', str(data)).group(1)
    ml_item['telefono']= phone_number
    ml_item['direccion'] = response.xpath('/html/body/div[1]/div/div/div[1]/main/div/div[1]/div[2]/div[1]/div/span[2]/text()').extract()
    comunidad = response.xpath('/html/head/script[3]/text()').extract()
    ciudad = re.search(r'"addressRegion":"(.*?)","postalCode"', str(comunidad)).group(1)
    ml_item['ciudad']= ciudad


    self.item_count += 1
    self.contador +=1
    if self.item_count > 9999:
        raise CloseSpider('item_exceeded')
    yield ml_item

Я могу сканировать только первую страницу, я пытаюсь найти hrefдля следующей страницы, но на следующей иконке со стрелкой ее нет. Моя последняя возможность - итерация счетчика по id

...