скрап для l oop реагирует каждый раз только на первый элемент - PullRequest
0 голосов
/ 22 марта 2020

Я пытался сканировать страницу со многими элементами "article", но l oop каждый раз возвращает только первый элемент (столько, сколько их элементов article).

for offer in response.xpath("//article"):
        product = Product() 
        product['kind'] = 'deal'
        product['portal'] = 'mydealz'
        product['link'] = offer.xpath("//a[@class='cept-dealBtn boxAlign-jc--all-c space--h-3 width--all-12 btn btn--mode-primary']/@href").get()
        product['merchant'] = offer.xpath("//div[@class='threadGrid']/div[@class='threadGrid-title']/a[@class='thread-title--list']/text()").get()
        #product['merchant'] = offer.xpath("//div[@class='threadGrid']/div[@class='threadGrid-title js-contextual-message-placeholder']/div[@class='overflow--fade']/a[@class='cept-merchant-link text--color-greyShade size--all-s']/span[@class='cept-merchant-link-term overflow--wrap-off']/span[@class='text--b text--color-brandPrimary cept-merchant-name']/text()").get()
        product['offer'] = offer.xpath("//div[@class='threadGrid']/div[@class='threadGrid-title js-contextual-message-placeholder']/strong[@class='thread-title']/a[@class='cept-tt thread-link linkPlain thread-title--list']/text()").get()
        #product['offer'] = offer.xpath("//div[@class='threadGrid']/div[@class='threadGrid-title js-contextual-message-placeholder']/strong[@class='thread-title']/a[@class='cept-tt thread-link linkPlain thread-title--list']/text()").get()
        product['crawlingdate'] = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        yield product
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...