Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What -t switch do in scrapy?

In scrapy tutorials said that for saving output to csv or any other format we should use this command:

scrapy crawl spider -o result.csv -t csv

in general we can use this command:

scrapy crawl my_spider -o file_name.extension -t extension

but I used this command without -t and there is no problem:

scrapy crawl spider -o result.csv

My question is what is role of -t?

like image 328
Sara Santana Avatar asked Mar 18 '26 09:03

Sara Santana


1 Answers

Whenever you are not sure, look into the source code.

According to the crawl.py source code, if you don't specify the format explicitly, Scrapy would detect it - the extension of the file name would be used as a format:

if not opts.output_format:
    opts.output_format = os.path.splitext(opts.output)[1].replace(".", "")

In your case csv would be used.

like image 172
alecxe Avatar answered Mar 19 '26 23:03

alecxe