donglao9606 2009-05-07 20:17
浏览 21

为什么PHP XPath找不到表元素,即使Firefox显示它们存在?

I am trying to pull an exact table during a "web scrape." Used cURL to pull page into $html, which succeeds fine.

Used Firebug to get exact XPATH to the table needed.

Code follows:

$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;

When executed, $summary->length is always zero. It doesn't pull that table node.

Any ideas?

  • 写回答

2条回答 默认 最新

  • dongliang1996 2009-05-07 20:26
    关注

    Firefox is liable to insert "virtual" tbody elements into tables that don't have them; do those elements exist in the original file?

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教