Exception Handling Functions

When scrapping a site there are times when you need to provide some event handling in the case of error.

For example a Fetch command may not return any data due to changes to the master source, so what do you do and how do you detect such errors.

Using the Interaction builder, many of these function are created automatically.in the "Error handling" tab. These functions can be used to assist in handling exceptions.


$t->contains( )

 Usually used after row() or rows() to determine if a matching string of text or HTML is found in the fetch results. Common uses:

Finding if a fetched source contains an error message so logic can be written into your Madl code. Using the Interaction builder, this function is created automatically in the "Error handling" tab.

Parameters   

 
 $search
A String a which you want to find in fetch results.

Return Values   

 
$t->result
A String. Returns true or false into variable $t 
$t->fetch("http://blinkmobile.com.au");
if($t->contains("Test for me")){
}
return $t->result;

 

$t->notcontains( )

  Usually used after row() or rows() to determine if a matching string of text or HTML is found in the fetch results. Common uses:

 Finding if a fetched source contains an error message so logic can be written into your Madl code. Using the Interaction builder, this function is created automatically in the "Error handling" tab.

Parameters   

 
 $search
A String a which you want to find in fetch results.

Return Values   

 
$t->result
A String. Returns true or false into variable $t 
$t->fetch("http://blinkmobile.com.au");
if($t->notcontains("Test for me")){
}
return $t->result;

 

 

$t->isblank( )

Usually used after row() or rows() in case nothing was found

Parameters   

 
 
None

Return Values   

 
$t->result
A String. containing your custom error message  into variable $t 
$t->fetch("http://blinkmobile.com.au");
if($t->isblank()){
 return "I Found No Data";
}
return $t->result;

 

Emails On Exceptions via the BMP Code Generator.

 Using the Interaction builder, this code is created automatically in the "Error handling" tab.

Emails can be sent if the results of a Fetch meet any of the following conditions:

  • Is Blank : Returns no result in $t.
  • Contains : Returns a specified string in the result in $t.
  • Does not contain : Does not contain a specified string in the result in $t.

 

Parameters   

 
 $The condition:
 (as explained above. ) 
The Return Message
A String. containing your custom error message  into variable $t 
Send email
 Yes or no for sending an email alert.
Email addressA string. containing a valid email address for the alert to be sent to.
Email Subject
A string containing an email subject title.
Email Body
A string containing information you wish to be sent in the email body.

Using the code generator will then produce the following code which incorporates $t->email madl. Click here more information on mADL Email functions.

$t->fetch("http://blinkmobile.com.au");
if($t->isblank()){
 $t->email("support@blinkmobile.com.au", "No Data found in your interaction", "The interaction found no data and need to be resolved.
Thanks.
");
 return "I Found No Data";
}
return $t->result;