Here's an example of the page that I need to extract data with simple html dom:
<li><a href="http://www.domain.com/games/game1"><img class="nimg" src="http://www.domain.com/content/icons/game1.jpg" alt="Play Cool game" />
Cool game</a></li>
I need url, jpg and title (cool game), not alt.
So far I found only solutions that managed to extract only one attribute, href
:
foreach($html->find('a') as $element) $links[] = $element->href;
Do you mean something like:
foreach($html->find('a') as $element) {
$links[] = array(
'href' => $element->href,
'title' => $element->title,
...
);
}
you can try something like this.
foreach($html->find('a') as $element) {
$img = $element->find('img',1);
$games[] = array(
'url' => $element->href,
'img' => $img->src,
'title' => $element->plaintext
)
}
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.