0

I am currently using symfony DOM-crawler for website scraping. I just wanna know how to select specific elements with the same class or name. I wanna use it also in tds.

here is the syntax I'm using currently:

$nameCrawler = $x_crawler->filter('.detail_text > .detail_info__content:nth-child(3) > p');

but it always return node empty. Is there anyway to achieve that? I can only scrape data from elements with a specific class name but elements with same class name I cannot scrape.

Here is the div structure:

<div class="parent">
    <div class="child">
        <p>test</p>
    </div>
    <div class="child">
        <p>test</p>
    </div>
    <div class="child">
        <p>test</p>
    </div>
    <div class="child">
        <p>test</p>
    </div>
    <div class="child">
        <p>test</p>
    </div>
</div>

lets say I want to get the p of 3rd child of class "child".

msg
  • 7,863
  • 3
  • 14
  • 33
jn_lance
  • 1
  • 6
  • The structure you provided doesn't match your selectors, it is advisable that you adapt your examples so they match and can be run by other people without having to invest time in fixing them. Ultimately, whatever fix we come up with might not reflect the real situation, so not many people is going to do that. That said, you can try an alternative syntax: `$crawler->filter('.parent')->children('.child')->eq(2)->children('p')` (zero-indexed). – msg Mar 22 '22 at 17:44

0 Answers0