如何编写 XPath 来捕获未标记的文本

发布于 2024-08-03 07:57:39 字数 446 浏览 1 评论 0原文

我试图从网站上删除客户评论,并遇到了一个有趣的设置。

<div class="Review">
  <img class="stars" etc>
  <b>ReviewerName</b>
  - yyyy-mm-dd
  <br/>
  <p>Review</p>
  <a>was this helpful links</a>
  <hr/>
  <br/>
  <!-- Repeat above for additional reviews. -->
</div>

我一生都无法想出一个能够捕获日期 (- yyyy-mm-dd) 的 XPath,因为它周围没有 HTML 格式。有人有解决办法吗?

乔恩

I'm trying to scrap customer reviews from a site and ran into an interesting set-up.

<div class="Review">
  <img class="stars" etc>
  <b>ReviewerName</b>
  - yyyy-mm-dd
  <br/>
  <p>Review</p>
  <a>was this helpful links</a>
  <hr/>
  <br/>
  <!-- Repeat above for additional reviews. -->
</div>

For the life of me I can't come up with an XPath that will capture the date (- yyyy-mm-dd), as there is no HTML formatting around it. Anyone have a solution?

Jon

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时光的容颜 2024-08-10 07:57:39

假设这样的结构:

<div class="Review">
    <img class="stars"/><b>ReviewerName</b> - yyyy-mm-dd<br/>
</div>

以下 xpath 选择日期yyyy-mm-dd

substring-after(/div/b/following-sibling::text()[1],' - ')

Assuming a structure like this:

<div class="Review">
    <img class="stars"/><b>ReviewerName</b> - yyyy-mm-dd<br/>
</div>

The following xpath selects the date yyyy-mm-dd

substring-after(/div/b/following-sibling::text()[1],' - ')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文