In the same html pageThere’re two different format of the same contain :
the first is :
<div class="gs"><h3 class="gsr"><a href="http://www.example1.com/">title1</a>
the second is :
<div class="gs"><h3 class="gsr"><span class="gsc"></span><a href="http://www.example2.com/">title2</a>
How to get links and titles in one code that can handle that two different format with simple_html_dom?
I’ve tried this code, but it doesn’t work :
foreach($html->find('h3[class=gsr]') as $docLink){
$link = $docLink->first_child();
echo $link->plaintext;
echo $link->href;
}
From the doc there seems to be a concept of Descendant Selectors
Then
Should do your job. [I’m not really aware of simple_html_dom btw 😉 Just a try]
EDIT
There is also nested selectors
So
Should also work