同一表中多个行的XPath

发布于 2025-01-31 09:00:41 字数 289 浏览 3 评论 0原文

我正在尝试为刮刀编写XPath。这是表中的第一行的给定XPATH:/html/hody/div [3]/div/div/div [2]/div [8]/div/div/table/tbody/tr [1]

我只需要提取与第一列中某些值相关的某些值。例如,第一列具有日期,第二列的数据与这些日期相对应。我只需要为某些包含“ 2015-03-14','2014-02-15'等日期的行编写XPath等。有没有办法添加这样的多个值?

到目前为止,我尝试了包含操作员,但仅适用于一个值[包含(。,'2015-03-14')]。我想添加多个日期。

I'm trying to write XPath for certain rows for a scraper. Here's the given XPath for only the first row in the table: /html/body/div[3]/div/div[2]/div[8]/div/table/tbody/tr[1]

I need to extract only certain values that relate to certain values in the first column. For example, the first column has dates and second column has data corresponding to those dates. I need to write XPath for only certain rows that contain dates '2015-03-14', '2014-02-15' and so on. Is there a way to add multiple values like this?

So far I've tried the contains operator but it only works for one value [contains(.,'2015-03-14')]. I want to add multiple dates.

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

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

发布评论

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

评论(1

飘然心甜 2025-02-07 09:00:41

尝试以下操作:

tr[td[1][contains(.,'2015-03-14') or contains(.,'2014-02-15')]]/td[2]

如果除了whitespace之外,第一列中没有其他内容,您也可以使用=使用归一化空间值,例如:

tr[td[1][normalize-space()[.='2015-03-14' or .='2014-02-15']]]/td[2]

它找到第二个TD的人与您的一个日期之一有第一个TD。

我跳过通往TR的路径以获得可读性,但这是:/html/hody/div [3]/div/div/div [2]/div [8]/div/div/div/table/tbody/code>,要添加课程

try this:

tr[td[1][contains(.,'2015-03-14') or contains(.,'2014-02-15')]]/td[2]

If besides whitespace there is nothing more in that first column you could also just use the = operator using the normalized-space value, like this:

tr[td[1][normalize-space()[.='2015-03-14' or .='2014-02-15']]]/td[2]

It finds those second td's who has a first td with one of your dates.

I skipped the path to the tr's for readability, but this: /html/body/div[3]/div/div[2]/div[8]/div/table/tbody/, has to be added off course

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文