简体   繁体   中英

PHP error using simple_html_dom

I'm using simple_html_dom to extract data from a website the code works great but it looks like it's searching for an object at the beginning. The error displays "Notice: Trying to get property of non-object" This is on the line of echo $e->children(0)->href . '
';

Here is the code:

<?php

//$searchURL = "site";
include 'simple_html_dom.php';

$site = 'http://espnfc.com/team/fixtures/_/id/359/league/eng.1/arsenal?cc=5739';
$html = file_get_html($site);


// Find all TD tags with "align=center"
foreach($html->find('td[align=center]') as $e)
echo $e->children(0)->href . '<br>';


?>

It should work. It will do that, if you are trying to get href from that children(0) , and that $e element does not have children.

$html = file_get_html('http://espnfc.com/team/fixtures/_/id/359/league/eng.1/arsenal?cc=5739');
foreach($html->find('td[align=center]') as $element) {
       if ($element->children(0)) { // work only when children exists
              echo $element->children(0)->href. '<br>';
       }
}

Look at my example for your specific case and read documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM