I am new to python and web scraping and I tried storing the scrapy data to a csv file however the output is not satisfactory.
Current csv output:
Title Image
Audi,Benz,BMW Image1,Image2,Image3
how i would like to view it in a csv file:
Title Image
Audi Image1
Benz Image2
BMW Image3
this is what is type in the terminal to run it:
scrapy crawl testscraper -t csv -o test.csv
Here's the spider.py:
class TestSpiderSpider(scrapy.Spider):
name = 'testscraper'
page_number = 2
start_urls = ['https://jamaicaclassifiedonline.com/auto/cars/']
def parse(self, response):
items = scrapeItem()
product_title = response.css('.jco-card-title::text').extract()
product_imagelink = response.css('.card-image img::attr(data-src)').getall()
items['product_title'] = product_title
items['product_imagelink'] = product_imagelink
items.append('items')
yield items
He's the code for items.py:
class scrapeItem(scrapy.Item):
product_title = scrapy.Field()
product_imagelink = scrapy.Field()
pass