这里我如何得到我的 dom 树:
$html = file_get_contents('somefile.html');
$dom = new DOMDocument();
@$dom->loadHTML($html);
$dom_document = new DomXPath($dom);
$dom_object = $dom_document->query('somePathHere');
$dom_object的html结构:
<div>
<a href='something'>some text here</a>
I want this
</div>
这是我需要的:
foreach($dom_object as $value){
echo $value->getElementsByTagName('a')->item(0)->nodeValue; //working properly
echo 'I want this' // I don't know how to get that 'I want this' text
}
精度:我想避免进行多个 xpath 查询。我想坚持我的……提前谢谢你。干杯。马克