How to find an element by attribute using QueryPath

1.1k Views Asked by At

I need to find all tables with width=230

So far I have:

foreach($qp->top('table')->get() as $table) {
    $width = $table->attr('width');
}

But I get a "Call to undefined method DOMElement::attr()" error.

2

There are 2 best solutions below

0
On

It seems, $table is a DOMElement, so probably you can do

$width = $table->getAttribute('width);
1
On

Try something like

$table->find('[width="230"]');