【发布时间】:2011-06-17 15:27:18
【问题描述】:
我很难获得第二个链接 href 和 Text。如何选择 class="secondLink SecondClass"。使用 PHP Dom,谢谢
<td class="pos" >
<a class="firstLink" href="Search/?List=200003000112097&sr=1" >
Firs link value
</a>
<br />
<a class="secondLink SecondClass" href="/Search/?KeyOpt=ALL" >
Second Link Value
</a>
</td
我的代码是
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
// grab all the on the page
$xpath = new DOMXPath($dom);
//$hrefs = $xpath->evaluate("/html/body//a[@class='firstLink']");// its working
$hrefs = $xpath->evaluate("/html/body//a[@class='secondLink SecondClass']");// not working
谢谢
【问题讨论】:
-
您的code is working。 XPath 是正确的。你做错了什么。
-
哇......它的工作原理。为什么它在这里不起作用。谢谢
-
在see左右切换类名时不起作用