Iterate only x times through a pattern match

Hi,

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.

How can that be achieved ?

Thanks you.

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.

// Loop through each of the data records.
for&#40; i = 0; i < dataSet.getNumDataRecords&#40;&#41;; i++ &#41;
&#123;
        // Only do something for the first 5 records.
        // Don't forget that Arrays and Hashtables typically start with zero.
        if &#40; i <= 4 &#41; &#123;
                // Store the current data record in the variable myDataRecord.
                myDataRecord = dataSet.getDataRecord&#40; i &#41;;
               
                // Output the "PRODUCT_NAME" value from the data record to the log.
                session.log&#40; "Product name&#58; " + myDataRecord.get&#40; "PRODUCT_NAME" &#41; &#41;;
        &#125;
&#125;

It will loop through your entire dataSet but you're controlling which records you want to deal with.

Hope that helps,

Scott