I have made a scrapy crawler that goes to this site https://www.cartoon3rbi.net/cats.html
then by first rule open the link to every show, get its title by parse_title method, and on third rule open every episode's link and get its name. its working fine, i just need to know how can i make a seperate csv file for each show's episodes's names with titles in parse_title method being used as name of the csv file. Any suggestions?
# -*- coding: utf-8 -*-
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
class FfySpider(CrawlSpider):
custom_settings = {
'CONCURRENT_REQUESTS': 1
}
name = 'FFy'
allowed_domains = ['cartoon3rbi.net']
start_urls = ['https://www.cartoon3rbi.net/cats.html']
rules = (
Rule(LinkExtractor(restrict_xpaths='//div[@class="pagination"]/a[last()]'), follow=True),
Rule(LinkExtractor(restrict_xpaths='//div[@class="cartoon_cat"]'), callback='title_parse', follow=True),
Rule(LinkExtractor(restrict_xpaths='//div[@class="cartoon_eps_name"]'), callback='parse_item', follow=True),
)
def title_parse(self, response):
title = response.xpath('//div[@class="sidebar_title"][1]/text()').extract()
def parse_item(self, response):
for el in response.xpath('//div[@id="topme"]'):
yield {
'name': el.xpath('//div[@class="block_title"]/text()').extract_first()
}