![](/img/trans.png)
[英]PHP: Simple HTML DOM Parser - how to get the element which has certain content?
[英]PHP: Simple HTML DOM Parser - how to get the element which has certain tag name?
在PHP中,我使用的是Simple HTML DOM Parser類。
我有一個HTML文件,它有多個和不同的標簽。
在這個HTML中有一個這樣的元素:
<a name="10418"><b> Hospitalist (Family Practitioner)</b></a>
所以我想找到名字=“10418”的 ' a '元素
我試過這個沒有運氣,因為我只想得到那個字符串。
$html_object = str_get_html($url);
$html_object=$html_object->find('a');
foreach ($html_object as $o) {
$a= $o->find("b");
echo $a[0];
}
嘗試另一個名為Tag Parse的庫。它簡單而有效。
$dom = new TagParse\TagDomRoot($html);
$a = $dom->find('a[name="10418"]');
我認為它比simple_html_dom更快,成本更低。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.