PHP dom获取具有多个css类名的标签类 [英] PHP dom to get tag class with multiple css class name
本文介绍了PHP dom获取具有多个css类名的标签类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法获取第二个链接href和文本。如何选择class =secondLink SecondClass。使用PHP Dom,谢谢
I have difficulties to get second link href and Text. How to select class="secondLink SecondClass". Using PHP Dom, Thank you
<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
谢谢
推荐答案
$hrefs = $xpath->evaluate("/html/body//a[contains(concat(' ',@class,' '),' secondClass ')
and (contains(concat(' ',@class,' '),' secondLink '))]"
来自此回答
这篇关于PHP dom获取具有多个css类名的标签类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文