Won't write output - but makes file
Hi,
I've just downloaded and started to use this program on Ubuntu Gutsy, and after following tutorials 1-3 I can pull the data result sets and have the Java example (and slightly modifed) script make the file but the files always come up empty and my log file shows a error after creating the file:
here is the output from the Hello World example on tutorial 1:
An error occurred while processing the script: Java Extracted Data
The error message was: The application script threw an exception: java.lang.NullPointerException BSF info: null at line: 0 column: columnNo
on the second instance I get this error :
Writing data to a file.
An error occurred while processing the script: wellness output
The error message was: Attempt to invoke method: get() on undefined variable or class name: dataRecord : at Line: 3.
here is the modified Java which I am using
FileWriter out = null;
try
{
session.log( "Writing data to a file." );
// Open up the file to be appended to.
out = new FileWriter( "wellness.txt", true );
// Write out the data to the file.
out.write( dataRecord.get( "First" ) + "\t" );
out.write( dataRecord.get( "Last" ) + "\t" );
out.write( dataRecord.get( "Company" ) + "\t" );
out.write( dataRecord.get( "Address" ) + "\t" );
out.write( dataRecord.get( "City" ) );
out.write( "\n" );
// Close up the file.
out.close();
}
catch( Exception e )
{
session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}
When I click on the "apply pattern to scraped data" where this script is added at the end (as After Pattern is Run) I get 5 results show up in the data set window.
where am I going wrong in geting these to output to my text file?
Won't write output - but makes file
pquery,
I'm sorry it's taken me this long to get back with you regarding this issue. Also, the solution is more straight forward than I realized at first. If you're calling your script "After pattern is applied" and you're referencing your extracted values assuming they're in the dataRecord, they're not. However, if you call your script "After each pattern application", then the variables would be in the the dataRecord scope.
Please have a look at the following table on [url=http://www.screen-scraper.com/support/docs/using_scripts.php#variable_scope]Variable Scope[/url] for a more complete explanation.
Thanks,
Scott
Won't write output - but makes file
I'm launching by the ubuntu application bar, almost as you would in windows.
I had updated my java repositories as well but that didn't seem to help.
should you be launching this from the terminal instead?
Won't write output - but makes file
pquery,
It seems like you're using a version of Java other than the one that comes with screen-scraper. How are you launching screen-scraper?
-Scott
Won't write output - but makes file
I've just updated my java reposotories, rebooted, rebuilt the Java and then re-run and am still running into the same issues...
Starting scraper.
Running scraping session: Hello World
Processing scripts before scraping session begins.
Scraping file: "Form Submission"
Form Submission: Preliminary URL: http://www.screen-scraper.com/tutorial/basic_form.php
Form Submission: Using strict mode.
Form Submission: Resolved URL: http://www.screen-scraper.com/tutorial/basic_form.php?text_string=Hello+World
Form Submission: Sending request.
Form Submission: Processing scripts before all pattern applications.
Processing script: "hello"
Writing data to a file.
An error occurred while processing the script: hello
The error message was: The application script threw an exception: java.lang.NullPointerException BSF info: null at line: 0 column: columnNo
Form Submission: Extracting data for pattern "Form data"
Form Submission: The following data elements were found:
Form data--DataRecord 0:
FORM_SUBMITTED_TEXT=Hello World
Form Submission: Processing scripts after a pattern application.
Form Submission: Processing scripts after all pattern applications.
Processing scripts after scraping session has ended.
Scraping session "Hello World" finished.
I'm not a java guy so can anyone tell me why it's trying to write to null when the file gets declared and then created? I've changed nothing in these examples