Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all HTML list element using Simple HTML Dom

Currently I am working on a project which requires me to parse some data from an alternative website, and I'm having some issues (note I am very new to PHP coding.)

Here's the code I am using below + the content it returns.

$dl = $html2->find('ol.tracklist',0);
print $dl = $dl->outertext;

The above code returns the data for what we're trying to get, it's below but extremely messy provided you would like to see click here.

However, when I put this in a foreach, it only returns one of the a href attributes at a time.

foreach($html2->find('ol.tracklist') as $li) 
{
    $title = $li->find('a',0);
    print $title;
}

What can I do so that it returns all of the a href elements from the example code above?

NOTE: I am using simple_html_dom.php for this.

like image 292
Herbo Avatar asked Oct 17 '22 14:10

Herbo


1 Answers

Based on the markup, just point directly to it, just get it list then point to its anchor:

foreach ($html2->find('ol.tracklist li') as $li) {
    $anchor = $li->find('ul li a', 0);
    echo $anchor->href; // and other attributes
}
like image 147
Kevin Avatar answered Oct 31 '22 11:10

Kevin