-1
<?php
$doc = new DOMDocument;
$doc->load("www.xyz.com/ABC");
$xpath = new DOMXpath($doc);
$elements = $xpath->query("*/div[@id='myspanId']");
?>

I am trying to get the value of "myspanId" from webpage "www.xyz.com/ABC".
But it displays error.

Also tried : $doc->loadHTML("www.xyz.com/ABC");

Venkata Krishna
  • 1,768
  • 2
  • 14
  • 21
  • What is your question? Why do you hide the error message? What was the expected outcome? What is the concrete outcome? Why don't you do error checking? – hakre Apr 19 '15 at 15:27
  • http://stackoverflow.com/questions/2571232/parse-html-with-phps-html-domdocument – hakre Apr 19 '15 at 15:29

1 Answers1

-1

You probably don't need the curl but this is how I would approach it.

$curl=curl_init( 'http://www.example.com/ABC' );
/* Set other curl options */
$response=curl_exec( $curl );
curl_close( $curl );


libxml_use_internal_errors( true );
$dom = new DOMDocument('1.0','utf-8');
$dom->validateOnParse=false;
$dom->standalone=true;
$dom->preserveWhiteSpace=true;
$dom->strictErrorChecking=false;
$dom->substituteEntities=false;
$dom->recover=true;
$dom->formatOutput=false;       
$dom->loadHTML( mb_convert_encoding( $response, 'utf-8' ) );    
$parse_errs=serialize( libxml_get_last_error() );
libxml_clear_errors();


/* there was a typo here - should be DOMXPath! */
$xpath=new DOMXPath( $dom );
$elements = $xpath->query("*/div[@id='myspanId']");
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
  • In which relation is this to the question at all? You don't give any explanations at alll to the code just that curl is not necessary (but still you post curl code). Puzzled at best. – hakre Apr 19 '15 at 15:25