getMatchingRegexPolicy

RetryPolicy RetryPolicyFactory.getMatchingRegexPolicy ( int retries, String regex )
RetryPolicy RetryPolicyFactory.getMatchingRegexPolicy ( int retries, String regex, String scriptOnFail )
RetryPolicy RetryPolicyFactory.getMatchingRegexPolicy ( int retries, String regex, Runnable runnableOnFail )

Description

Policy that requires a Regular Expression to match the page content (including headers) in order to be considered valid.

Parameters

  • retries How many times max to retry before failing
  • regex A Regular expression that must match the page content for the page to be considered valid
  • scriptOnFail/runnableOnFail (optional) What to run (script or Runnable) if the policy shows an error on the page. This will be run just before the page is downloaded again. The script or Runnable will be executed in the current thread, so the scrapeable file will not be redownloaded until this runnable or script has finished executing.

Return Value

The RetryPolicy to set in the ScrapeableFile

Change Log

Version Description
5.5.29a Available in all editions.

Examples

Set a matching regex policy

 import com.screenscraper.util.retry.RetryPolicyFactory;
 // Require the response to contain the text "Google.com".  Since this is a regex, the . must have a \ before it
 scrapeableFile.setRetryPolicy(RetryPolicyFactory.getMatchingRegexPolicy(5, "Google\\.com", "Rotate Proxy"));