为什么PHP XPath找不到表格元素,即使Firefox显示它们存在? [英] Why doesn't PHP XPath find table elements even though Firefox shows they exist?
本文介绍了为什么PHP XPath找不到表格元素,即使Firefox显示它们存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在web scrape中试图拉一个精确的表格。
使用cURL将页面拉入$ html,成功了。
I am trying to pull an exact table during a "web scrape." Used cURL to pull page into $html, which succeeds fine.
使用Firebug获取所需表格的确切XPATH。
Used Firebug to get exact XPATH to the table needed.
代码如下:
$dom = new DOMDocument($html);
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$summary = $xpath->evaluate('/html/body/table[5]/tbody/tr/td[3]/table/tbody/tr[8]/td/table');
echo "Summary Length: " . $summary->length;
执行时,$ summary->长度始终为零。它不拉那个表节点。
When executed, $summary->length is always zero. It doesn't pull that table node.
任何想法?
推荐答案
p> Firefox可以在没有它们的表中插入virtual tbody
元素。这些元素是否存在于原始文件中?
Firefox is liable to insert "virtual" tbody
elements into tables that don't have them; do those elements exist in the original file?
这篇关于为什么PHP XPath找不到表格元素,即使Firefox显示它们存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文