Symfony - DomCrawler 通过自定义属性获取元素
Symfony - DomCrawler get element by custom attribute
我需要过滤这个标签
<div dir=3D"ltr">
我试过了
$crawler = $crawler->filter('div[dir=3D"ltr"]');
但是不行...
Expected "]", but <identifier "D" at 6> found.
有什么想法吗?
$crawler->filter('div')->each(function (Crawler $node, $i) {
if ($node->attr('dir') == '3D"ltr"') {
// It's the element
}
});
这是我所知道的最好的方法。不确定它是否是最好的,但它会起作用。
您正在尝试使用 quoted-printable encoded. You need to decode the data before treating it like HTML. PHP has the built-in function quoted_printable_decode()
的数据来为您执行此操作。
$html = quoted_printable_decode($html);
$crawler = new Crawler($html);
$crawler = $crawler->filter('div[dir="ltr"]');
我需要过滤这个标签
<div dir=3D"ltr">
我试过了
$crawler = $crawler->filter('div[dir=3D"ltr"]');
但是不行...
Expected "]", but <identifier "D" at 6> found.
有什么想法吗?
$crawler->filter('div')->each(function (Crawler $node, $i) {
if ($node->attr('dir') == '3D"ltr"') {
// It's the element
}
});
这是我所知道的最好的方法。不确定它是否是最好的,但它会起作用。
您正在尝试使用 quoted-printable encoded. You need to decode the data before treating it like HTML. PHP has the built-in function quoted_printable_decode()
的数据来为您执行此操作。
$html = quoted_printable_decode($html);
$crawler = new Crawler($html);
$crawler = $crawler->filter('div[dir="ltr"]');