Invoke Script

Adding Script Association/Trigger

A script is executed in screen-scraper by associating it with some event, such as before or after an extractor pattern is applied to the text of a web page. The script we've just written needs to be executed after screen-scraper has requested the web page and extracted the data we need from it.

Return to the extractor pattern we just created by clicking on the Form submission scrapeable file, then on the Extractor Patterns tab. In the lower section of your extractor pattern, click on the Add Script button.

By default it adds an association to the first, alphabetically, script in your instance of screen scraper. If this is not Write extracted data to a file then click on the script name and select it. The trigger (when it will run) is defined in the When to Run column. For our script select After pattern is applied.

Our Write extracted data to a file script will be invoked after screen-scraper has applied the Form data extractor pattern to the web page. That is, once the extractor pattern has applied as many times as it needs to (which, in this case, is only once), it will invoke the script.

The curious might be wondering a bit more about the difference between After pattern is applied and After each pattern match. Consider a web page that contains a table with 10 rows. We might create an extractor pattern that matches a single row in the table. The extractor pattern would match 10 times: once for each row in the table. If we associated a script with the extractor pattern and told it to run After pattern is applied, the script would only get executed one time (i.e., after the pattern has matched as many times as it needs to). If we had indicated that the script should run After each pattern match, it would get executed 10 times: once time for each match the pattern makes. In the current case, the pattern only matches one time, so it doesn't make a difference which association we specify.