0

I'm grabing some information using PHP, 'DomDrawler' and 'Xpath Helper'
When I query some node information, there is no matched value returned.
I don't know why it doesn't work.

Page enter image description here

<?php
require  '../vendor/autoload.php';
use GuzzleHttp\Client;
use Symfony\Component\DomCrawler\Crawler;

function showcourse($response){
    $data    = []; //Store
    $crawler = new Crawler();
    $crawler->addHtmlContent($response);

    try {
        $data['name'] = $crawler->filterXPath('/html/body/div[@id=\'brief\']
     /table/tbody/tr[1]/td[1]/table[@class=\'items\'][1]/tbody/tr/td[@class=
     \'cover\'][1]/a[@id=\'NEU01000219238\']/img/@src')->text();
    } catch (\Exception $e) {
        echo "No nodes  ";
    }
    print_r($data);
    //echo $response;
}
?>

Result enter image description here

Nothing is returned.

Naresh
  • 16,698
  • 6
  • 112
  • 113
Raven Xu
  • 11
  • 4

1 Answers1

0

First, your shown xpath examples are different from each other ... without having a xml document its just wild guessing, but this kind of error is most likely an xpath expression issue. Try to reduce the complexity of the xpath expression until an expected result returns. Or try to begin with the simplest expression /html. If this also does not return anything try // as expression ... if there is also no result, the error is most probably not your expression. Double check if a valid document returns from your response.

Jim Panse
  • 2,220
  • 12
  • 34