sonia k sonia k - 5 months ago 8x
PHP Question

returns blank output for xpath

i am trying to list all the links and names on the page. i keep getting bank output for the code below

$html = file_get_contents($url);

and the nodes part is

$nodes = $my_xpath->query( '//table[@class="social_list"]/tbody/tr' );

foreach( $nodes as $node )

$title = $my_xpath->evaluate( 'td[1]/a"]', $node );
$link = $my_xpath->evaluate( 'td[1]/a/@href"]', $node );

echo $title.",".$link."<br>";


note right click on the site is disabled and i use developer tools to inspect the code for the element in chrome


The query

$nodes = $xpath->query('//table[@class="social_list"]/tbody/tr/td/a');

Inside foreach to get title and URL

$title = $node->textContent;
$href = $node->getAttribute('href');