0

I need filter this tag

<div dir=3D"ltr">

I tried it

$crawler = $crawler->filter('div[dir=3D"ltr"]');

But not work...

Expected "]", but <identifier "D" at 6> found.

Any ideas?

  • `css-selector` uses XPath under the covers, and that's invalid XML so *I don't think* there's a way around that using `filter` or `filterXPath`. Other than fixing the markup. That *looks* like an encoding artifact, since `3D` decodes to `=`. – msg Sep 05 '19 at 19:38
  • @msg It is the html generated by gmail... – Maria Brands Sep 05 '19 at 19:56

2 Answers2

2

You're trying to work with data that is quoted-printable encoded. You need to decode the data before treating it like HTML. PHP has the built-in function quoted_printable_decode() to do this for you.

$html = quoted_printable_decode($html);
$crawler = new Crawler($html);
$crawler = $crawler->filter('div[dir="ltr"]');
miken32
  • 42,008
  • 16
  • 111
  • 154
0
            $crawler->filter('div')->each(function (Crawler $node, $i) {
                if ($node->attr('dir') == '3D"ltr"') {
                    // It's the element
                }
            });

This is the best way I know of to do it. Not sure if it's the best but it will work.

Lulceltech
  • 1,662
  • 11
  • 22