Compare commits

...

2 Commits

Author SHA1 Message Date
Yohann Dedy ec40af2cce Iteration des pages suivantes fonctionnelle 2019-11-27 00:05:34 +01:00
Yohann Dedy 557c76c2ca Base fonctionnelle 2019-11-26 23:33:46 +01:00
1 changed files with 9 additions and 2 deletions

View File

@ -20,9 +20,14 @@ class GetEpisodesSpider(scrapy.Spider):
}
def parse(self, response):
for sel in response.xpath('//section[@class="emission-diffusions-list"]'):
url_episode = response.urljoin(sel.xpath('.//a[@class="preview-list-element-link"]/@href').extract_first())
for sel in response.xpath('//section[@class="emission-diffusions-list"]//a[@class="preview-list-element-link"]/@href'):
url_episode = response.urljoin(sel.extract())
next_page = response.xpath('//link[@rel="next"]/@href')
yield scrapy.Request(url_episode, callback = self.parse_episode)
if next_page:
next_url = response.urljoin(next_page.extract_first())
yield scrapy.Request(url=next_url)
def parse_episode(self, response):
page_episode = scrapy.Selector(response)
@ -33,4 +38,6 @@ class GetEpisodesSpider(scrapy.Spider):
for field, xpath in self.episode_fields.items():
loader.add_xpath(field, xpath)
loader.add_value('url_page', response.url)
yield loader.load_item()