jeddi
10-23-2009, 10:04 AM
Hi,
I am new to using the DOMDocument() function set
and am practicing on website that I know.
this is my script, but I am not getting any output.
I alştered the script to show the contents of $dom
and I find that it is empty ??
$target_url = "http://www.expert-world.com/";
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
echo "<br>Starting<br>Target_url: $target_url";
// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$page= curl_exec($ch);
if (!$page) {
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
//echo "<br>Page: $page"; THIS echoed the page fine when uncommented.
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($page);
echo "<br>Dom: $dom";
// grab all the on the page
$xpath = new DOMXPath($dom);
echo "<br>Xpath: $xpath";
?>
The result:
Starting
Target_url: http://www.expert-world.com/
Shouldn't I be seeing something more?
Does this mean that my php5.2 is not equipped with DOMDocument() ?
I am new to using the DOMDocument() function set
and am practicing on website that I know.
this is my script, but I am not getting any output.
I alştered the script to show the contents of $dom
and I find that it is empty ??
$target_url = "http://www.expert-world.com/";
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
echo "<br>Starting<br>Target_url: $target_url";
// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$page= curl_exec($ch);
if (!$page) {
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
//echo "<br>Page: $page"; THIS echoed the page fine when uncommented.
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($page);
echo "<br>Dom: $dom";
// grab all the on the page
$xpath = new DOMXPath($dom);
echo "<br>Xpath: $xpath";
?>
The result:
Starting
Target_url: http://www.expert-world.com/
Shouldn't I be seeing something more?
Does this mean that my php5.2 is not equipped with DOMDocument() ?