Skip to content

Instantly share code, notes, and snippets.

@Alino
Last active August 29, 2015 14:12
Show Gist options
  • Save Alino/2d90d60b7ecc9408e454 to your computer and use it in GitHub Desktop.
Save Alino/2d90d60b7ecc9408e454 to your computer and use it in GitHub Desktop.
<?php
/**
* This script is meant to be run from terminal or command line
*/
error_reporting(E_ERROR | !E_WARNING | E_PARSE);
$dom = new DOMDocument();
if (!$dom->loadHTMLFile('http://www.pixmania.co.uk/roadworks/playmobil-4820-ladder-unit/04373247-a.html')) {
die("there was an error downloading the product page, now exiting...");
}
// get product name
$tags = $dom->getElementsByTagName('h1');
foreach ($tags as $tag) {
if ($tag->getAttribute('class') == 'pageTitle') {
echo 'Product: ' .trim($tag->nodeValue)."\n";
break;
}
}
// get product price
$tags = $dom->getElementsByTagName('ins');
foreach ($tags as $tag) {
if ($tag->getAttribute('itemprop') == 'price') {
echo 'Price: ' .trim($tag->nodeValue)."\n";
break;
}
}
// get product availability
$tags = $dom->getElementsByTagName('strong');
foreach ($tags as $tag) {
if ($tag->getAttribute('class') == 'available nowrap weee') {
echo 'In Stock: ' .trim($tag->nodeValue)."\n";
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment