php - Using simplehtmldom to grab a text snippet -
i'm trying use simplehtmldom script @ text. html structure follows
<div id="posts"> <div align="center"> <several levels of html> <strong>xxx</strong> </several levels of html> </div> <div align="center"> <several levels of html> <strong>ignore</strong> </several levels of html> </div> <div align="center"> <several levels of html> <strong>ignore</strong> </several levels of html> </div> </div>
the text i'm trying @ xxx string, in first <strong>
tags inside first <div>
attribute align="center"
, inside <div>
id="posts"
. i'm not interested in text in <div align="center">
tags further down.
the "several levels of html" include messy nested tables etc.
my code: i'm using descendant selectors , i'm "skipping" through several levels of html. reason why print_r
shows "trying property of non-object"
?
$html = file_get_html($page_1); $es = $html->find('div#posts div[align=center] strong'); print_r($es->plaintext); die;
strangely enough statement returns same "trying property of non-object"
result. doing wrong?
$es = $html->find('div#posts');
2 possible reasons :
- in
$html = file_get_html($page_1);
,$page_1
may not url. if it's string containing html usestr_get_html
in$html = str_get_html('<div id="hello">hello</div><div id="world">world</div>');
instead. - the html contains more 1
div#posts
(which shouldn't).
Comments
Post a Comment