[英]PHP Simple HTML DOM - How to find the table by a particular value in TD?
[英]How to find data and get text from html table td element next to it, without attribute using PHP Simple DOM?
我正在使用 simple_html_dom.php 來完成這項任務。
我更清楚如何從這種表格中獲取值(明文)“Data c”或“Data F”?
有沒有辦法首先找到值為“Data A”的 td,然后使用 next_sibling() 或 previous_sibling() 獲取並輸出值“Data C”?
如何在 web 包含在 HTML 表中的數據的下一個/之前執行此“查找並獲取數據”?
<table class="xyz">
<tbody>
<tr>
<td>Data A<p>data b</p>
</td>
<td>Data C</td>
</tr>
<tr>
<td>Data D<p>data e</p>
</td>
<td>Data F</td>
</tr>
</tbody>
</table>
還是我應該使用其他一些技術? 請你能幫我嗎?
謝謝你!
您可以很容易地使用 javascript 從各種表格單元格中檢索內容 - 不確定這是否是您的意思?
<script>
var col=document.querySelectorAll('table.xyz td');
for( var n in col ) if( n && col[n] && col[n].nodeType==1 ) console.log( 'Cell:%d Type:%s Value:%s',n,col[n].tagName, col[n].innerHTML );
</script>
will output
-----------
Cell:0 Type:TD Value:Data A<p>data b</p>
Cell:1 Type:TD Value:Data C
Cell:2 Type:TD Value:Data D<p>data e</p>
Cell:3 Type:TD Value:Data F
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.