Search code examples
phpsymfonydomcrawler

Getting a data-attribute with DomCrawler


Is it possible to get the data with DomCrawler?

$cralwer->attr('class') gets me the node's class attribute, but ->attr('data-something') or ->attr('something') always results in null.

Edit: tagging PHP also because I tried while manipulating the DomElement object from php (using ->attributes->getNamedItem()) and it still won't work. I'm wondering if it's just not possible to return a data attribute at all?


Solution

  • Got it. The data attribute in the source code was written as such : data-SomeAttribute.

    Trying to access it with the cases ($crawler->attr('data-SomeAttribute') is what is failing here. Doing it without the case ($crawler->attr('data-someattribute') works perfectly fine!