Java Nul error despite scripts working and data extracted
I have a simple scrape session pulling two peices of datae from 1 table row. The extractor patterns are working correctly (when I apply pattern to last scraped data it displays correctly for both extractor patterns). I have also edited each token multiple times to verify "save in session variable' is checked for both.
I am running my Write_Data_To_File script after each pattern is applied.
No matter what I check the log always shows:
java.lang.NullPointerException BSF info:null at line: 0 column: columnNo
Please suggest what may be causing this?
The Interpreted Java code for my Write_Data_To_File script is:
// Output a message to the log so we know that we'll be writing the text out to a file.
session.log( "Writing data to a file." );
// Create a FileWriter object that we'll use to write out the text.
out = new FileWriter( "data.txt", true );
// Remove & signs from artist name
artistName = session.getVariable( "artist_name" );
artistName = artistName.replaceAll( "&", "&" );
session.setVariable( "artist_name", artistName );
// Remove & signs from track name
trackName = session.getVariable( "track_name" );
trackName = trackName.replaceAll( "&", "&" );
session.setVariable( "track_name", trackName );
// Write out the text.
//Write out the individual scraped elements------------------------------
out.write( session.getVariable( "track_name" )+ "\t");
out.write( session.getVariable( "artist_name"+ "\t"));
//Insert the line break to seperate records------------------------------
out.write("\r");
// Close the file.-------------------------------------------------------
out.close();
Java Nul error despite scripts working and data extracted
Hi,
The error is occurring because you're missing a parenthesis in one of your lines of code. This:
out.write( session.getVariable( "artist_name"+ "\t"));
should be this:
out.write( session.getVariable( "artist_name") + "\t");
Just a tip on debugging errors like this, it often helps to insert lots of "session.log" statements. You can see which of those lines get output to the log, then, when one of them doesn't, the preceding line or two probably contains the bug.
On an unrelated note, even with that fix I don't think this scraping session will do what you intend it to. It looks like you're wanting it to write out each artist and track name together. In order for that to happen, you're going to need to create a single extractor pattern that pulls both of those elements, then invokes your "Write_Data_To_File" script "After each pattern application" rather than "After pattern is applied".
Kind regards,
Todd Wilson
Scraping sessions and file available for reveiw
I have uploaded all the files I used at:
[url]http://www.completeagency.com/scrapesupport/scrapingfiles.zip[/url]