P
P
prozrost2018-09-09 20:27:10
symfony
prozrost, 2018-09-09 20:27:10

Symfony DomCrawler. How to select a node with a specific text?

I use Symfony DomCrawler to scrape the site. For example, there is a table with many rows and columns. I need specific column data, first row for example. There is a structure like this:

<tr class="info">
      <td>Год рождения</td>
      <td>1953<td>
   <tr>

And I need to select a specific value of the Year of Birth. (Followed by lines with data of a similar structure, which I also need to extract)
I did it first through the eq function. (I found the second element in the line and extracted the value). But this is not a very good way, since it only changes a little html and the order of the elements - everything does not work. I wanted to find the text "Year of birth" through the filterXPath function. It turned out something like this:
$name =  $short->filterXPath('//text()[contains(.,"Дата Рождения")]')->text();

But even it does not work in this way for me to find the element. And I couldn't find a similar "search" anywhere. Tell me how you can write something universal and get around my problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-11-15
@alexandrraizer

The question is not completely clear ..
but in order to get the tr block in this situation:
finds an element that has an element inside that contains only text that contains our phrase and does not contain tags.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question