Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

$t→fetch()

Given a URL and post data, the fetch function makes a HTTP request and sets $t->result to be the resulting source code.

...

Return Values   

 
$t->result
A String.
 Returns the last requested source into $t->result

...

 

$t->submitForm( )

Often known as a "PassThru"... On occasions when you are retrieving a page source into an Interaction you may require authorisation from a login form.

...

Code Block
themeRDark
languagephp
title Example
linenumberstrue
$t->fetch("[http://support.blinkmobile.com.au/");] 


 $t->submitForm( 0,
    array(
    'username'=>'YourUserName',
    'passwd'=>'YourPassword'
    )
);
return $t->result;

// Page source returned here for additional processing

 

$t→fetch_info[]

Provides access to the cURL info about the most recent $t->fetch() that was performed. See http://php.net/manual/en/function.curl-getinfo.php

Code Block
themeRDark
languagephp
title Example
linenumberstrue
$t->fetch('http://www.google.com');echo $t->fetch_info['http_code']; // returns '200'

 

Using DOMDocument To Display For Fetch Results

Often you may come up against a web page which is hard to scrape using the standard mADL builder method on $t->rows( )

In this case we are looking at retrieving all the hyperlinks from a web directory page but it is dynamically build and we cannot capture a regular expression pattern for the fetch.

You can use The DOMDocument class from php to resolve this.

You still use $t->Fetch() but you add the result to an array and then iterate the array to a screen output.

Code Block
themeRDark
languagephp
title DOMDocument Example
linenumberstrue
 
$t->fetch("http://partystarter.com.au/browse_categories.php?id=2013");

$wsDom = new DOMDocument();
$wsDom->loadHTML($t->result);
foreach($wsDom->getElementsByTagName('a') as $thisLink) {

if ($thisLink->getAttribute('href')!=""){


echo "<a href=\" ".$thisLink->getAttribute('href')  ." 
\">".$thisLink->getAttribute('title')."</a><br>";


};

View a live example