Skip to content Skip to sidebar Skip to footer

Parse Html Table With Dom And Xpath

I'm trying to parse an HTML Table with XPath. The URL is: click here. I use FireBug to see page's DOM and i understand the container i need. &l

Solution 1:

Your query is fetching all table rows so far. In the next step, loop over these results (in PHP) and access the rows as needed. You might either want to use direct DOM access or XPath, whatever you prefer.

For using XPath, use an XPath expression that starts querying at the current context, and pass the current row as such. Use numerical predicates to limit to the row you're looking for. For example, to query the team name (in the third table cell, XPath counts 1-indexed), use something like

$tableRows = $xpath->query('//div//div//div[2]//div/div//table//tr');
foreach ($tableRowsas$row) {
    $team = $xpath->query('./td[3]/a', $row)->item(0)->textContent;
}

Querying the class attributes might also be possible, but they seem to be used rather arbitrarily.

Now, read the other table rows with similar queries, construct the resulting map and append it to the $scores array.

Post a Comment for "Parse Html Table With Dom And Xpath"