I make a parser using symfony / Domcrawler and there is a need to get the href value of some elements. How to do it?

<a class="Place__headerLink Place__title Link Link--shade-80 h5 small Place--lineClamping" href="https://club-drozdy.relax.by/" target="_blank" title="Drozdy Club" data-reactid=".yfuzkhv2j8.5.0.0.1.0.0.$10336959.2.1.0.0.0.0">Drozdy Club</a> 

And so I get the value itself

 $crawler->filter('div.PlaceList__itemWrapper:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > a:nth-child(1)'); 
  • Where is your code? - teran
  • Added a piece of HTML'a. From which you need to take - RedScreed
  • one
    and what's there, ->attr('href') or ->link()->getUri() don't work? or does your search for the necessary element return null ? - teran
  • ->attr('href') does everything as it should. I didn’t seem to be watching the documentation carefully) - RedScreed

1 answer 1

According to the documentation , the attr('attr_name') method is used to access node attributes.

This is the first selection of the current selection:

 $class = $crawler->filterXPath('//body/p')->attr('class'); 

that is, in this case, attr('href') .

The same page describes the interaction with links, as well as an example of using the auxiliary class Link , with its getUri method . An example of using something like this:

 $nodeCrawler->filter('a')->link()->getUri(),