5

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?

Jean-Philippe Murray
  • 1,208
  • 2
  • 12
  • 34

1 Answers1

3

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!

Jean-Philippe Murray
  • 1,208
  • 2
  • 12
  • 34