Answer the question
In order to leave comments, you need to log in
How to parse a certain cell of an HTML table and several subsequent ones?
Hello.
Stuck on the following issue. I have an HTML table:
<table>
<tr>
<td class="past">текст</td>
<td class="past">текст</td>
<td class="past">текст</td>
..........................
<td class="today">текст</td>
<td>текст</td>
<td>текст</td>
</tr>
<tr>
<td>текст</td>
<td class="weekend">текст</td>
<td class="weekend">текст</td>
<td>текст</td>
<td>текст</td>
<td>текст</td>
</tr>
</table>
<td class="today">
<tr>
<td class="today">
Answer the question
In order to leave comments, you need to log in
On the advice of 'AlexP11223' and after googling, I posted this code.
I feel that it is far from ideal, but everything works.
Comments are accepted.)
libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile("http://calendar.zoznam.sk/sunset-pl.php?city=3080866");
$xpath = new DomXPath($dom);
$today = $xpath->query("//td[@class='today']");
$nodes1 = $xpath->query("//td[@class='today']/following::td[1]");
$nodes2 = $xpath->query("//td[@class='today']/following::td[2]");
$nodes3 = $xpath->query("//td[@class='today']/following::td[3]");
$nodes4 = $xpath->query("//td[@class='today']/following::td[4]");
header("Content-type: text/plain");
foreach ($today as $i => $node) {
echo $node->nodeValue, "\n";
}
foreach ($nodes1 as $i => $node1) {
echo $node1->nodeValue, "\n";
}
foreach ($nodes2 as $i => $node2) {
echo $node2->nodeValue, "\n";
}
foreach ($nodes3 as $i => $node3) {
echo $node3->nodeValue, "\n";
}
foreach ($nodes4 as $i => $node4) {
echo $node4->nodeValue, "\n";
}
$today = $xpath->evaluate('string(//td[@class="today"])');
$first = $xpath->evaluate('string(//td[@class="today"]/following::td[1])');
$second = $xpath->evaluate('string(//td[@class="today"]/following::td[2])');
$third = $xpath->evaluate('string(//td[@class="today"]/following::td[3])');
$fourth = $xpath->evaluate('string(//td[@class="today"]/following::td[4])');
echo $today."<br>",
$first."<br>",
$second."<br>",
$third."<br>",
$fourth;
Why parse reg. HTML expressions?
stackoverflow.com/a/1732454/964478
There is, for example, XPath.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question