【发布时间】:2014-08-26 06:59:28
【问题描述】:
我有一个从网站中提取整数值的代码。我想知道我是否可以将所有这些整数相加并显示总和。
<?php
header('Content-Type: text/html; charset=utf-8');
$grep = new DoMDocument();
@$grep->loadHTMLFile("http://www.lelong.com.my/Auc/List/BrowseAll.asp");
$finder = new DomXPath($grep);
$class = "CatLevel1";
$nodes = $finder->query("//*[contains(@class, '$class')]");
foreach ($nodes as $node) {
$span = $node->childNodes;
echo str_replace(array('(', ')'), '', $span->item(1)->nodeValue);
echo '<br/>';
}
?>
期望的输出: 9768 9321 11407 31611 36506
总数:345664
谢谢!
【问题讨论】:
标签: php html xpath web-scraping domdocument