【发布时间】:2021-02-01 18:11:09
【问题描述】:
我有一个可以提取类别并显示它们的 php 代码。然而, 我仍然无法提取随之而来的数字(没有括号)。 需要将类别和编号分开(不要一起提取)。 也许使用正则表达式等做另一个 for 循环......
这是代码:
<?php
$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 $span->item(0)->nodeValue."<br>";
}
?>
有什么办法可以做到吗?谢谢!
这是我想要的输出:
Arts, Antiques & Collectibles : 9768<br>
B2B & Industrial Products : 2342<br>
Baby : 3453<br>
etc...
【问题讨论】: