如何为 HTML DOM 元素创建 XPATH? 例如,“/HTML/BODY/DIV[1]/TABLE[1]/TR[2]/TD[1]/INPUT”。
给定一个 DOM 元素如何得到这个 XPATH 字符串? 有什么想法吗?
谢谢,
达特巴约。
最佳答案
可以新建一个domdocument,然后导入节点元素
$DD= new DOMDocument('1.0', 'utf-8');
$DD->loadXML( "<html></html>" );
$DD->documentElement->appendChild($DD->importNode($DE,true));
然后你可以在 domelement 中使用 xpath:
$xpathe=new DOMXPath($DD);
关于html - 如何为 HTML DOM 元素创建 XPATH?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1333183/