Writing to a CSV

When I scrap a list of websites for data it writes the data to a csv just fine (actually when the number is more than 3 digits like 4000 it puts the "4" in column A and "000" in column B but I dont mind that) but it doesnt skip a line when there is no data to be found. So if the second website doesnt have data in it but every other site does then all my information is offset by one. I would rather a 0 when there is no data found - like a place holder - so my websites and data match up.

I have attached my code.

Thanks!
Dan

FileWriter out = null;

try
{
session.log( "Writing data to a file." );

// Open up the file to be appended to.
out = new FileWriter( "youtuberesults.csv", true );

// Write out the data to the file.
    out.write( dataRecord.get( "view" ) + "\t" );
    out.write( "\r\n" );

// Close up the file.
out.close();

}
catch( Exception e )

{
session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}

To add quotes: out.write("\""

To add quotes:

out.write("\"" + dataRecord.get( "view" ) + "\"\t");

It looks like that code is

It looks like that code is set to only run "after each pattern match" so if you're pattern doesn't match, the code isn't run, and you don't get an empty on the CSV.

To deal with the split numbers, you need to either get rid of the comma in the number, or wrap it in quotes.