Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 716
Jean-Philippe Murray Avatar asked Oct 18 '22 14:10

Jean-Philippe Murray


1 Answers

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!

like image 192
Jean-Philippe Murray Avatar answered Oct 21 '22 02:10

Jean-Philippe Murray