[Python] I’m trying to export data to a CSV file with semicolon separator ";" [duplicate]

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    While using Scrapy, I’m trying to export data to a CSV file, and it’s working. However, the separator used is a comma (","), but I need it to be a semicolon (";") instead.

    I’m currently running the command:

    scrapy runspider Intro_Scrapy.py -o video.csv

    How can I change the separator to ";" in the exported CSV file?

    Here is my hole code (only for learning):

    from scrapy.item import Field
    from scrapy.item import Item
    from scrapy.spiders import Spider
    from scrapy.selector import Selector
    from scrapy.loader import ItemLoader

    class Pregunta(Item):
    id = Field()
    pregunta = Field()
    descripcion = Field()

    class StackOverFlowSpider(Spider):
    name = "MiPrimerSpider"
    custom_settings = {
    "USER_AGENT": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
    }

    start_urls = ["https://stackoverflow.com/questions"]

    def parse(self, response):
    sel = Selector(response)
    preguntas = sel.xpath("//div[@id ='questions']//div[@class='s-post-summary--content']")
    print(preguntas)

    for pregunta in preguntas:
    item = ItemLoader(item = Pregunta(), selector = pregunta)
    item.add_xpath('pregunta','.//h3/a/text()')
    item.add_xpath('descripcion',".//div[contains(@class,'excerpt')]/text()")
    item.add_value('id', 1)
    yield item.load_item()

    Continue reading...

Compartilhe esta Página