【问题标题】:php xpath screen scrape issuephp xpath屏幕抓取问题
【发布时间】:2011-01-20 22:53:56
【问题描述】:

好吧,这看起来很简单,但我根本无法让这个编码工作......

$html = new DOMDocument();
@$html->loadHtmlFile('http://www.groupon.com/deals/the-newfoundland-shop');
$xpath = new DOMXPath( $html );
$nodelist = $xpath->query( "/html/body/div[@id='global_container']/div[@id='main']/div[@id='content']/div/div[1]/div[2]/div[@id='number_sold_container']/table[1]/tbody/tr/td" );
foreach ($nodelist as $n){
echo $n->nodeValue."\n";
}
$buys = "$n->nodeValue";

在我松开它之前请帮忙...

谢谢

【问题讨论】:

标签: php xpath screen-scraping


【解决方案1】:

尝试将这种语法用于 XPath -

/xhtml:html/xhtml:body/xhtml:div[@id='global_container'] ...

如果不帮助检查您的 XPath 是否正常(它真的很长)

【讨论】:

    【解决方案2】:

    第一个常见问题解答:页面看起来是正确的 XHTML,因此您需要使用一些前缀注册 XHTML 名称空间 URI http://www.w3.org/1999/xhtml,并在 XPath 表达式中使用该前缀。

    第二个常见问题:您应该注意原始来源没有tbody 元素。这是由浏览器添加的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 2016-01-11
      • 2011-06-03
      • 2014-05-22
      • 1970-01-01
      • 2013-03-02
      相关资源
      最近更新 更多