Xpath / PHP:匹配类子字符串的问题

问题描述 投票:0回答:1

我试图在p元素的class属性中匹配一个简单的子字符串但是得到错误:

$pElements = $crawler2
  ->filter(
 "p[contains(@class, 'price')]"); 
  // Expected operator, but <delimiter "(" at 10> found

  // "descendant-or-self::p[contains(@class, 'price')"); 
  // Unexpected pseudo-element "::p" found not at the end of a selector

我从这里得到的第二个(注释)选择语句的前缀:https://symfony.com/doc/current/components/css_selector.html

我正在使用这个库与Goute在PHP中进行网页抓取。

从错误(在服务器错误日志中)看起来xpath是坏的。谁能看到这个错误?

php xpath
1个回答
0
投票

首先,你没有关闭]支架 在"p[contains(@class, 'price')]"函数中尝试这个字符串:filter

© www.soinside.com 2019 - 2024. All rights reserved.