Answer the question
In order to leave comments, you need to log in
How to parse data with a specific value?
Hello!
There is a web page on which there is a regularly changed table. In the code of this table, this code is repeated N-th number of times
<tr>
<td class="highlightable group">ГРУППА</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">НЕ ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">НЕ ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">НЕ ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">НЕ ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
<tr>
<td class="highlightable group">ПОДХОДИТ</td>
<td class="pnum highlightable">НОМЕР</td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ</p><p class="pteacher">ИМЯ<span class="pcab"></span></p></td>
<td class="highlightable onepair"><p class="pname">ПРЕДМЕТ 2</p><p class="pteacher">ИМЯ 2<span class="pcab">НОМЕР 2</span></p></td>
</tr>
Answer the question
In order to leave comments, you need to log in
$dom = new DOMDocument;
$dom->loadXML($html);
$content = '';
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//td[.="ПОДХОДИТ"]/..') as $row) {
$content .= $dom->saveXML($row) . PHP_EOL;
}
echo $content;
https://ideone.com/p3zvcJ
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question