runOnError
void runOnError ( )
Description
Runs this code when the page had an error. This could include things such as rotating the proxy. This code will be executed just before the page is downloaded again.
Parameters
This method takes no parameters
Return Value
This method returns void
Change Log
Version | Description |
---|---|
5.5.29a | Available in all editions. |
Examples
Create a custom RetryPolicy
import com.screenscraper.util.retry.RetryPolicy;
_log = log;
_session = session;
RetryPolicy policy = new RetryPolicy()
{
Map errorMap = new HashMap();
boolean isError() throws Exception
{
errorMap.put("Was Error On Request", scrapeableFile.wasErrorOnRequest());
return scrapeableFile.wasErrorOnRequest();
}
void runOnError() throws Exception
{
session.executeScript("Rotate Proxy");
}
Map getErrorChecksMap() throws Exception
{
return errorMap;
}
boolean resetSessionVariablesBeforeRescrape()
{
return true;
}
boolean shouldLogErrors()
{
return true;
}
int getMaxRetryAttempts()
{
return 5;
}
boolean resetReferrerBeforeRescrape()
{
return false;
}
void runOnAllAttemptsFailed()
{
_log.logError("Failed to fix errors with the retry policy, stopping scrape");
_session.stopScraping();
}
};
scrapeableFile.setRetryPolicy(policy);
_log = log;
_session = session;
RetryPolicy policy = new RetryPolicy()
{
Map errorMap = new HashMap();
boolean isError() throws Exception
{
errorMap.put("Was Error On Request", scrapeableFile.wasErrorOnRequest());
return scrapeableFile.wasErrorOnRequest();
}
void runOnError() throws Exception
{
session.executeScript("Rotate Proxy");
}
Map getErrorChecksMap() throws Exception
{
return errorMap;
}
boolean resetSessionVariablesBeforeRescrape()
{
return true;
}
boolean shouldLogErrors()
{
return true;
}
int getMaxRetryAttempts()
{
return 5;
}
boolean resetReferrerBeforeRescrape()
{
return false;
}
void runOnAllAttemptsFailed()
{
_log.logError("Failed to fix errors with the retry policy, stopping scrape");
_session.stopScraping();
}
};
scrapeableFile.setRetryPolicy(policy);
mikes on 11/21/2011 at 3:32 pm
- Printer-friendly version
- Login or register to post comments