1

I am a bit confused about selecting one class between it's siblings... Html structure like below.

<ul class="pipeLink">
  <li class="pg">1</li><li class="pg"><a href="/wedding/clientList/?pn=2&amp;tdfkn=14">2</a></li>
  <li class="pg"><a href="/wedding/clientList/?pn=3&amp;tdfkn=14">3</a></li>
  <li class="pg"><a href="/wedding/clientList/?pn=4&amp;tdfkn=14">4</a></li>
  <li class="pg"><a href="/wedding/clientList/?pn=5&amp;tdfkn=14">5</a></li>
  <li class="pg"><a href="/wedding/clientList/?pn=6&amp;tdfkn=14">6</a></li>
  <li class="pg"><a href="/wedding/clientList/?pn=7&amp;tdfkn=14">7</a></li>
  <li class="pg"><a href="/wedding/clientList/?pn=8&amp;tdfkn=14">8</a></li>
  <li class="lastChild">
      <a href="/wedding/clientList/?pn=2&amp;tdfkn=14">next 30</a></li>
</ul>

There are 2 ul.pipeLine class in the page. On the top of the page and bottom. I just want to grab first or second ul.pipeLine and iterate the a tag's attribute in it. So I tried it with the code below.

$links = $response->filter("ul.pipeLink")->last()->each(function($node){
    return $node->filter("li a")->attr("href");
});

But when I use last() or first() or eq(0) etc... it's only getting one attribute inside the a tag, nothing else. Although I wanted to grab only one ul.pipeLine class in the page and iterate inside it.

I mean expected output should be like:

/wedding/clientList/?pn=2&amp;tdfkn=14
/wedding/clientList/?pn=3&amp;tdfkn=14
/wedding/clientList/?pn=4&amp;tdfkn=14
/wedding/clientList/?pn=5&amp;tdfkn=14
/wedding/clientList/?pn=6&amp;tdfkn=14
/wedding/clientList/?pn=7&amp;tdfkn=14
/wedding/clientList/?pn=8&amp;tdfkn=14

But it's like:

/wedding/clientList/?pn=2&amp;tdfkn=14

Is it possible to make it happen?

tate
  • 49
  • 7

1 Answers1

2

Okay, I solved the problem and posting it here as an answer for anyone who face this later.

$links = $response->filter("ul.pipeLink")->last()->children("li a")->each(function($node){
    return $node->attr("href");
});
tate
  • 49
  • 7