kimuraframework
kimuraframework copied to clipboard
How to create empty JSON when no records where scrapped?
I am crawling a property site and when there are no properties on the site, the existing json on the disk is not being overwritten.
How to ensure that JSON is written irrespective of records found or not.
The workaround is to create empty JSON before crawling open_spider callback
# Empty file before start crawling
def self.open_spider
File.open('path/to/output.json', 'w') { |file| file.write([].to_s) }
end