我很难在HTML表格的海洋中找到DYNAMIC-TEXT值。
我试过$html->find("th[plaintext*=Type")
,从这里开始,我想访问兄弟姐妹,但什么都不返回。这是表结构
<table>
<tbody>
</tbody>
<colgroup>
<col width="25%">
<col>
</colgroup>
<tbody>
<tr class="odd">
<th colspan="2">Name</th>
</tr>
<tr class="even">
<th width="30%">Type</th>
<td>DYNAMIC-TEXT</td>
</tr>
</tbody>
</table>
我希望输出是DYNAMIC-TEXT的文本但是动作输出什么都没有
谢谢
在你的代码$html->find("th[plaintext*=Type")
你想使用attribute selector *=
但没有属性plaintext
。
但是有一个属性宽度值为30%。您可以使用模式^[0-9]+%$
检查1+位后跟一个百分号。
如果你找到了结果,你可以得到next_sibling并从中获得plaintext。
例如:
$html = str_get_html($str);
foreach ($html->find("th[width*=^[0-9]+%$]") as $value) {
echo $value->next_sibling()->plaintext;
}
结果:
DYNAMIC-TEXT