【问题标题】:Using xPath expression to fetch first part of text using substring-before使用 xPath 表达式使用 substring-before 获取文本的第一部分
【发布时间】:2015-06-02 18:22:22
【问题描述】:

我试图仅捕获字符串的 first 部分,但作为新手,我对如何格式化 xPath 表达式感到困惑。在下表中,我只想要第三行/第三单元格中的律师姓名 - 在中断标记之前。

我可以通过以下方式进入牢房:

//tr[contains(.,'Plaintiff')]/following-sibling::tr[contains(.,'Attorney:')]/td[3]

但是如何编写包含“substring-before”的 xPath 表达式以返回
之前的所有内容?

这是我正在使用的表:

<table class="data">
  <thead>
   <tr class="head">
    <th scope="COL">Type</th>
    <th scope="COL">Name</th>
    <th scope="COL">Disposition</th>
   </tr>
 </thead>
<tbody>
 <tr class="odd">
  <td class="">Plaintiff</td>
   <td class="">
   “Citibank, N.A.”
   <br>
   “None”
   </td>
   <td class="">CV-BT EntryJgmt-Clerk Default</td>
   </tr>
   <tr class="even xh-highlight">
   <td class="">&nbsp;</td>
   <td class=""><b>Attorney:</b></td>
   <td class="">
   “Sue Yu”
   <br>
   “Dewey, Cheatum &amp; Howe Law Offices
   ,
   515 Burnitt St, Suite 400, San Jose, Ca  95119”
   </td>
  </tr>
  <tr class="odd">
   <td>Defendant</td>
   <td>
   “Emma Royds”
   <br>
   “None”
   </td>
   <td>CV-BT EntryJgmt-Clerk Default</td>
  </tr>
 </tbody>
</table>

【问题讨论】:

    标签: xpath


    【解决方案1】:

    之前没有子字符串:

    //tr[contains(.,'Plaintiff')]/following-sibling::tr[contains(.,'Attorney:')]/td[3]/br[1]/preceding-sibling::text()[1]
    

    这应该可行

    【讨论】:

    • 是的。完美运行。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多