XML | Scrape Shop
Bookmark this!
Muster this!
 Home   

Implementation

Retrieving by XML file

The XML files are:
  • For all results for a website: http://www.scrapeshop.co.uk/Site Code.xml
    • eg. http://www.scrapeshop.co.uk/aBcDeFgHiJ.xml
  • For all results for a product: http://www.scrapeshop.co.uk/Site Code_Product name.xml
    • eg. http://www.scrapeshop.co.uk/aBcDeFgHiJ_product1.xml

This can be easily from php:

function getProducts($productName) { // Returns arrayed collection of the product name or all products
if ($productName) $productname="_".$productname;
$pages=array();
$id="aBcDeFgHiJ"; // Your site code
$xml = simplexml_load_file("http://www.scrapeshop.co.uk/".$id.$productname.".xml";
foreach($xml->children() as $child) {
$pages[$child->getName()]=array();
foreach($child->children() as $page){
$thisPage=array();
foreach($child->children() as $kid) $thisPage[$kid->getName()]=$kid;
$pages[$child->getName()][]=$thisPage;
}
}
return $pages; // $pages contains an array collection of the single product
}

To process the response from getProducts(), use something like:

$products=getProducts(null);

foreach($products as $product=>$p) {
if ($product=="error") {
echo("Error:".$p);
}else if ($product=="action") {
echo("Action:".$p);
}else{
echo($product);
foreach($p as $page) {
echo("<div style='border:1px solid #bbbbbb'>");
foreach($page as $record) foreach($record as $k=>$v) {
// retrieves the product's fields and values
echo("<div>$k = $v</div>");
}
echo("</div>");
}
}
}