Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parse(self, response):
- with open('quotes-data.csv', 'w') as output_file:
- csv_writer = csv.writer(output_file, delimiter='t', quotechar="'")
- csv_writer.writerow(['title', 'author', 'description', 'tags'])
- i = 1
- for quote in response.xpath('//div[@class="book"]'):
- title = quote.xpath('./div[@class="title"]/text()').extract_first()
- author = quote.xpath('.//div[@class="author"]/text()').extract_first()
- description = quote.xpath('.//div[@class="description"]/text()').extract_first()
- tags = quote.xpath('.//div[@class="keywords"]/span[@class="tag"]/text()').extract()
- tags = ' '.join(tags)
- tags = f'"{tags}"'
- author = f'"{author}"'
- description = f'"{description}"'
- row = [i, author, title, description, tags]
- csv_writer.writerow(row)
- i += 1
- yield {
- 'title': title,
- 'author': author,
- 'tags': tags,
- 'description': description
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement