2

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

My code is

// 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

Thank you

hakre
  • 193,403
  • 52
  • 435
  • 836
Andy
  • 41
  • 2
  • 5

2 Answers2

2
 $hrefs = $xpath->evaluate("/html/body//a[contains(concat(' ',@class,' '),' secondClass ')
          and (contains(concat(' ',@class,' '),' secondLink '))]"

from this answer

Community
  • 1
  • 1
Cadell Christo
  • 3,105
  • 3
  • 21
  • 19
-1

you can pick it by selecting your td having class pos and selecting anchor tags. then you cann control your returing array to get your specific anchor tag

Awais Qarni
  • 17,492
  • 24
  • 75
  • 137