Only export to CSV if not empty?

Questions & Answers about Helium Scraper 3
Post Reply
Posts: 22
Joined: Sat Feb 02, 2013 1:01 am

Only export to CSV if not empty?

Post by yeti » Wed Feb 23, 2022 3:42 pm

Hi Juan,

Things are working well with my project.

Something else I am looking to achieve, which would improve the success rate of my results...

'If' there was an issue with the scrape, which resulted in an empty CSV - is there a way to make sure that the CSV is not exported?

Importing an empty CSV into my website would cause problems, as it is configured to delete data from the website that no longer exists in the CSV.

Thank you.

Site Admin
Posts: 521
Joined: Mon Dec 06, 2010 8:39 am

Re: Only export to CSV if not empty?

Post by webmaster » Sat Mar 05, 2022 8:09 am

I'm assuming you have a table that you don't want to export if it's empty? Supposing you have a table called Test, you can first create a query by right-clicking your table (Data.Test in this case) in Project Explorer, selecting Create Query, leaving everything with the default values and pressing OK. Then you can do this:

Code: Select all

   ·  Sequence.Length
         ·  Sequence.First
               ·  Query.Test
as length
   ·  =
         ·  length
         ·  1
   ·  Action.ExportData
         ·  "Test"
         ·  "test.csv"
         ·  true
   ·  Action.Log
         ·  "Data was empty."
What that's doing is taking the first row in the query (this is just an optimization) and getting the length, which can be 1 if the table has contents or 0 if it's empty, and then exporting only if the length is 1.
Juan Soldi
The Helium Scraper Team

Post Reply