Php 如何在QueryPath中选择这些未分类的元素

Php 如何在QueryPath中选择这些未分类的元素,php,regex,querypath,Php,Regex,Querypath,以下是所讨论的HTML: <div class="logo-wrapper"> <ul> <li> Contact: <strong>I need this</strong> </li> <li> Location: <strong>and this</strong> </li>

以下是所讨论的HTML:

<div class="logo-wrapper">
    <ul>
      <li>
          Contact: <strong>I need this</strong>
      </li>
      <li>
        Location: <strong>and this</strong>
      </li>
    </ul>
</div>

  • 联系人:我需要这个
  • 位置:和此
我的第一反应是在li元素上使用eq(0)和eq(1),但有时接触点或位置可能不存在,li的顺序会改变。我还尝试使用filterPreg()来选择“联系人:”和“位置:”文本,但这似乎没有达到我的预期效果


除了使用
find('.logo wrapper')->text()
然后使用标准的regexp来获取所需内容之外,有没有办法将其保存在QueryPath中?

您想用php或javascript来查找它?(因为你的问题没有javascript标记)-还有,有没有机会给那些li类?我使用的是PHP,不幸的是没有,不能给li类(那太容易了:))我怀疑你只能用QueryPath函数来实现。因为你无法区分是联系人还是地点。看起来您必须为爬虫程序至少使用一次regexp;)该死的耻辱。QP中的filterPreg()搜索函数是否不适用于此?我确实尝试了
find('.logo wrapper')->filterPreg('/Contact://')->find('strong')->text()
,但如果我没记错的话,它返回了两组li文本