I'm trying to use Zend_Dom_Query to get some specific content from a webpage. I got a query working to get the content from one dom-element. Now i want to select a second dom-element to get this content also.
This is the html:
<div class="blocks">
<div class="w2">
<h2>Some title</h2>
<p>some text</p>
<p>more text</p>
<p class="more-info"><a href="#">link</a></p>
</div>
<div class="w2">
<h2>Some title</h2>
<p>some text</p>
<p>more text</p>
<p class="more-info"><a href="#">link</a></p>
</div>
</div>
My code so far:
$client = new Zend_Http_Client();
$client->setUri('http://awsomewebsite');
$result = $client->request('GET');
$response = $result->getBody();
$dom = new Zend_Dom_Query($response);
foreach ($dom->query('div.w2') as $content) {
echo $content->getElementsByTagName('h2')->item(0)->nodeValue; // this gives me the h2 value
echo $content->getElementsByTagName('a')->item(0)->getAttribute('href');
}
Now the problem is when there are more anchor links this solution isn't working. My question is: What is the correct way to select multiple elements? Or can i use a new query inside this foreach to select the right element?