Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php xpath屏幕擦伤问题_Php_Xpath_Screen Scraping - Fatal编程技术网

php xpath屏幕擦伤问题

php xpath屏幕擦伤问题,php,xpath,screen-scraping,Php,Xpath,Screen Scraping,好的,这看起来很简单,但我无法让这个编码工作在所有 $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']/

好的,这看起来很简单,但我无法让这个编码工作在所有

$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";
在我松开它之前请帮忙


谢谢,请尝试将此语法用于XPath-

/xhtml:html/xhtml:body/xhtml:div[@id='global\u container']


如果没有帮助,请检查您的XPath是否正常(确实很长)

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


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

(tipp)@Gordon你的冒险意识在哪里?;-)@middaparka读完第5章后,我就没有那么大胆了;)