我正在使用此代码从该站点获取一些金属名称(例如:铜、铝):http ://www.kitcometals.com/ 。这些名称位于页面左侧名为实时现货价格的表格中。
这是我的代码:
<?php
$url = "http://www.kitcometals.com/";
$html = file_get_contents($url);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xp = new DOMXPath($dom);
$qs = $xp->query("//table[@dwcopytype='CopyTableRow']/tbody/tr[@class='spot']/td[@class='menuB']");
foreach($qs as $q)
{
echo $q->textContent."<br>";
}
?>
我已经在 google chrome 的 Xpath 应用程序中测试了这个 XPath。它可以很好地显示该表中的每个金属名称。显示:
铜镍铝锌铅铀
但它不适用于 PHP 代码。有人请找出问题吗?