I have a 'results' page which can list many items in repeating table cells. I can extract them fine; however only want to run the 'details' page for the first 5 it finds.
There are a few ways you can do this. If you're using the professional or enterprise editions you have access to the [url=http://screen-scraper.com/support/docs/api_documentation.php#addToVariable]addToVariable()[/url] method that makes this a bit cleaner and easier. Otherwise, here's what I'd recommend.
From your extractor pattern text, call a script "After pattern is applied". Within your script include something like the following.
// Loop through each of the data records.
for( i = 0; i < dataSet.getNumDataRecords(); i++ )
{
// Only do something for the first 5 records.
// Don't forget that Arrays and Hashtables typically start with zero.
if ( i <= 4 ) {
// Store the current data record in the variable myDataRecord.
myDataRecord = dataSet.getDataRecord( i );
// Output the "PRODUCT_NAME" value from the data record to the log.
session.log( "Product name: " + myDataRecord.get( "PRODUCT_NAME" ) );
}
}
It will loop through your entire dataSet but you're controlling which records you want to deal with.
Iterate only x times through a pattern match
tohide,
There are a few ways you can do this. If you're using the professional or enterprise editions you have access to the [url=http://screen-scraper.com/support/docs/api_documentation.php#addToVariable]addToVariable()[/url] method that makes this a bit cleaner and easier. Otherwise, here's what I'd recommend.
From your extractor pattern text, call a script "After pattern is applied". Within your script include something like the following.
for( i = 0; i < dataSet.getNumDataRecords(); i++ )
{
// Only do something for the first 5 records.
// Don't forget that Arrays and Hashtables typically start with zero.
if ( i <= 4 ) {
// Store the current data record in the variable myDataRecord.
myDataRecord = dataSet.getDataRecord( i );
// Output the "PRODUCT_NAME" value from the data record to the log.
session.log( "Product name: " + myDataRecord.get( "PRODUCT_NAME" ) );
}
}
It will loop through your entire dataSet but you're controlling which records you want to deal with.
Hope that helps,
Scott