![]() |
ImplementationRetrieving (and adding) a single productYour website can call the results for a single product. If the product is new, Scrape Shop will add it or explain why it can't. The Url to call is http://www.scrapeshop.co.uk/get.php?id=Site Code&url=URL encode product address&product=URL encode product name This can be easily from php:
function getProduct($url,$productName) { // Returns arrayed collection of the product
$pages=array();
}
$id="aBcDeFgHiJ"; // Your site code $xml = simplexml_load_file("http://www.scrapeshop.co.uk/get.php?id=$id&url=".urlencode($url)."&product=".urlencode($productName)); foreach($xml->children() as $child) { // cycle through the product types (only one)
if ($child->getName()=="error" || $child->getName()=="action") {
}// Catch any error or action response
}else{
$pages[$child->getName()]=$child;
$pages[$child->getName()]=array(); // Create an array named the product name
}
foreach($child->children() as $page){ // cycle through the pages (only one)
$thisPage=array();
}
foreach($child->children() as $kid) $thisPage[$kid->getName()]=$kid; // cycle through the product details and place them in the array $pages[$child->getName()][]=$thisPage; return $pages; // $pages contains an array collection of the single product To process the response from getProduct(), use something like:
$products=getProduct("http://www.misco.co.uk/applications/SearchTools/item-details.asp?EdpNo=312392","Projector");
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>"); | ![]() |