extractData

DataSet scrapeableFile.extractData ( String text, String extractorPatternName ) (professional and enterprise editions only)

Description

Manually apply an extractor pattern to a string.

Parameters

  • text The string to which the extractor pattern will be applied.
  • extractorPatternName Name of extractor pattern in the scrapeable file, as a string. Optionally the scraping session and scrapeable file where the extractor pattern can be found can be specified in the form [scraping session:][scrapeable file:]extractor pattern.

Return Values

Returns DataSet on success. Failures will be written out to the log as errors.

Change Log

Version Description
4.5 Available for professional and enterprise editions.

An example of how to manually extract data is available.

Examples

Extract DataSet

 // Applies the "PRODUCT" extractor pattern to the text found in the
 // productDescriptionText variable. The resulting DataSet from
 // extractData is stored in the variable productData.

 DataSet productData = scrapeableFile.extractData( productDescriptionText, "PRODUCT" );

Loop Through DataRecords

 // Expanded example using the "PRODUCT" extractor pattern to the text found in the
 // productDescriptionText variable. The resulting DataSet from
 // extractData is stored in the variable myDataSet, which has multiple dataRecords.
 // Each myDataRecord has a PRICE and a PRODUCT_ID.<br />

 myDataSet = scrapeableFile.extractData( productDescriptionText, "PRODUCT" );
 for (i = 0; i < myDataSet.getNumDataRecords(); i++) {
     myDataRecord = myDataSet.getDataRecord(i);

     session.setVariable("PRICE", myDataRecord.get("PRICE"));
     session.setVariable("PRODUCT_ID", myDataRecord.get("PRODUCT_ID"));
 }

Extractor Pattern from another Scrapeable File

 // Apply extractor pattern "PRODUCT" from "Another scrapeable file"
 // to the variable productDescriptionText

 DataSet productData = scrapeableFile.extractData( productDescriptionText, "Another scrapeable file:PRODUCT" );

Extractor Pattern from another Scraping Session

 // Apply extractor pattern "PRODUCT" from "Another scrapeable file"
 // in "Other scraping session" to the variable productDescriptionText

 DataSet productData = scrapeableFile.extractData( productDescriptionText,
                        "Other scraping session:Another scrapeable file:PRODUCT" );