php scrapping

function file_get_contents_curl($url)
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);      

$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$htmldata = file_get_contents_curl('http://bascousa.com/kraft-self-seal-bubble-mailers-bmb857ss.html');
$error = false;
if($htmldata){
$domdocument= new DOMDocument;
$internalErrors = libxml_use_internal_errors(true);
$domdocument->loadHTML($htmldata);
libxml_clear_errors(); //remove errors for yucky html
$readhtml_xpath = new DOMXPath($domdocument);
$name = array();

$articlename       =   $readhtml_xpath->query('//div[contains(@id,"content_features")]/div');
if($articlename->length > 0 && !$error){
foreach($articlename as $container)
{
echo $container->textContent.'<br>';
}
}
}

Comments

Popular posts from this blog

Blogger post using PHP API

Pin payment laravel