Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create empty JSON when no records where scrapped? #59

Open
amitpatelx opened this issue Jul 14, 2021 · 1 comment
Open

How to create empty JSON when no records where scrapped? #59

amitpatelx opened this issue Jul 14, 2021 · 1 comment

Comments

@amitpatelx
Copy link

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.

@amitpatelx
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant