Web Interface Interactions

Overview

These methods are used in connection with the web interface of screen-scraper. Their use will provide the interface with more detailed information regarding the state of a running scrape. If you are not running the scrapes using the web interface then these methods are not particularly helpful to you.

As the web interface is an enterprise edition feature, these methods are only available in enterprise edition users.

addToNumDuplicateRecordsScraped

void session.addToNumDuplicateRecordsScraped ( Object value ) (enterprise edition only)

Description

Add to the value of duplicate records scraped. (As opposed to new or error records.)

Parameters

  • value Value to be added to the count. Usually a integer but if it is given a string (e.g. "10") it will try to transform it into an integer before adding.

Return Values

Returns void.

Change Log

Version Description
7.0 Available for enterprise edition.

Examples

Record New Records Scraped

 // Adds 10 to the value of new records scraped.
 session.addToNumDuplicateRecordsScraped(10);

Have session record each time a new record saved to the database

// In script called "After each pattern match"
import java.sql.PreparedStatement;
import java.sql.ResultSet;

dm = session.getv("_DM");
con = dm.getConnection();

try
{
        String sql = "SELECT id FROM table WHERE did = ?";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, dataRecord.get("ID"));
        ResultSet rs = pstmt.executeQuery();
        if (rs.next())
        {
                log.log("---Already in DB");
                session.addToNumDuplicateRecordsScraped(1);
        }
        else
        {
                session.scrapeFile("Results");
        }
}
catch (Exception e)
{
        log.logError(e);
        session.setFatalErrorOccurred(true);
        session.setErrorMessage(e);    
}
finally
{
        con.close();   
}

addToNumErrorRecordsScraped

void session.addToNumErrorRecordsScraped ( Object value ) (enterprise edition only)

Description

Add to the value error records. (As opposed to duplicate or new records.)

Parameters

  • value Value to be added to the count. Usually a integer but if it is given a string (e.g. "10") it will try to transform it into an integer before adding.

Return Values

Returns void.

Change Log

Version Description
7.0 Available for enterprise edition.

Examples

Record New Records Scraped

// Adds 10 to the value of new records scraped.
session.addToNumErrorRecordsScraped(10);

Have session record each time a dataRecord is missing a vital datam

// In script called "After each pattern match"
if (sutil.isNullOrEmptyString(dataRecord.get("VITAL_DATUM")))
{
    log.logError("Missing VITAL_DATUM");
    session.addToNumErrorRecordsScraped(1);
}

addToNumNewRecordsScraped

void session.addToNumNewRecordsScraped ( Object value ) (enterprise edition only)

Description

Add to the value of new records scraped. (As opposed to duplicate or error records.)

Parameters

  • value Value to be added to the count. Usually a integer but if it is given a string (e.g. "10") it will try to transform it into an integer before adding.

Return Values

Returns void.

Change Log

Version Description
7.0 Available for enterprise edition.

Examples

Record New Records Scraped

 // Adds 10 to the value of new records scraped.
 session.addToNumNewRecordsScraped(10);

Have session record each time a new record saved to the database

// In script called "After each pattern match"
dm = session.getv("_DM");
dm.addData("db_table", dataRecord);
dm.commit("db_table");
if (dm.flush())
{
        session.addToNumNewRecordsScraped(1);
}

addToNumRecordsScraped

void session.addToNumRecordsScraped ( Object value ) (enterprise edition only)

Description

Add to the value of number of records scraped.

Parameters

  • value Value to be added to the count. Usually a integer but if it is given a string (e.g. "10") it will try to transform it into an integer before adding.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

Record Number of Records Scraped

 // Adds 10 to the value of the number of records scraped.
 session.addToNumRecordsScraped( 10 );

Have session record each time a DataRecord exists

 // In script called "After file is scraped"

 // Adds number of DataRecords in DataSet
 // to the value of the number of records scraped.

 session.addToNumRecordsScraped( dataSet.getNumDataRecords() );

See Also

appendErrorMessage

void session.appendErrorMessage ( String errorMessage ) (enterprise edition only)

Description

Append an error message to any existing error messages.

Parameters

  • errorMessage Error message that should be added, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

User Specified Error

 // First set the flag indicating that an error occurred.
 session.setFatalErrorOccurred( true );

 // Append an error message.
 session.appendErrorMessage( "An error occurred in the scraping session." );

See Also

getErrorMessage

String session.getErrorMessage ( ) (enterprise edition only)

Description

Get the current error message.

Parameters

This method does not receive any parameters.

Return Values

Returns current error message, as a string.

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

Write Error Message to the Log

 // Output the current error message to the log.
 session.log( "Error message: " + session.getErrorMessage() );

See Also

getFatalErrorOccurred

boolean session.getFatalErrorOccurred ( ) (enterprise edition only)

Description

Determine the fatal error status of the scrape.

Parameters

This method does not receive any parameters.

Return Values

Returns whether a fatal error has occurred, as a boolean .

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

Write Fatal Error State to Log

 // Output the "fatal error" state to the log.
 session.log( "Fatal error occurred: " + session.getFatalErrorOccurred() );

See Also

getNumRecordsScraped

int session.getNumRecordsScraped ( ) (enterprise edition only)

Description

Get the number of records that have been scraped.

Parameters

This method does not receive any parameters.

Return Values

Returns number of records scraped, as a integer.

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

Write Number of Records Scraped to Log

 // Outputs the number of records that have been scraped to the log.
 session.log( "Num records scraped so far: " + session.getNumRecordsScraped() );

See Also

resetNumRecordsScraped

void session.resetNumRecordsScraped ( ) (enterprise editions only)

Description

Reset the count on the number of scraped records.

Parameters

This method does not receive any parameters.

Return Values

Returns void.

Change Log

Version Description
5.0 Available for all editions.

Examples

Reset Count

// Clear number of records scraped
session.resetNumRecordsScraped();

See Also

setErrorMessage

void session.setErrorMessage ( String errorMessage ) (enterprise edition only)

Description

Set the current error message.

Parameters

  • errorMessage Desired error message, as a string.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

Specify an Error Message

 // First set the flag indicating that an error occurred.
 session.setFatalErrorOccurred( true );

 // Append an error message.
 session.setErrorMessage( "An error occurred in the scraping session." );

Web Interface Feedback

 // Append an error message. Without flagging it as an error.
 // This will hijack the error message so it is more just a
 // status message. Don't hijack if there was a fatal error.

 if ( !session.getFatalErrorOccurred() )
 {
     session.appendErrorMessage( "Scraping Page: " + session.getv( "PAGE" ) );
 }

See Also

setFatalErrorOccurred

void session.setFatalErrorOccurred ( boolean fatalErrorOccurred ) (enterprise edition only)

Description

Set the fatal error status of the scrape.

Parameters

  • fatalErrorOccurred Desired fatal error status to set, as a boolean.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

Set Fatal Error Flag

 // Set the flag indicating that an error occurred.
 session.setFatalErrorOccurred( true );

See Also

setNumRecordsScraped

void session.setNumRecordsScraped ( Object value ) (enterprise edition only)

Description

Set the number of records that have been scraped.

Parameters

  • value Value to set the count of the number of records scraped.

Return Values

Returns void.

Change Log

Version Description
4.5 Available for enterprise edition.

Examples

Set the Number of Records Scraped

 // Sets the value of the number of records scraped to 10.
 session.setNumRecordsScraped( 10 );

See Also