【问题标题】:IMPORTXML Xpath with contains (Google Sheets)包含包含的 IMPORTXML Xpath(Google 表格)
【发布时间】:2020-09-24 20:05:36
【问题描述】:

当前公式:

=IMPORTXML(
"https://int.soccerway.com/international/europe/uefa-cup/20202021/3rd-qualifying-round/r59325/",
"//div[@class='match-card match-hour' and ..//td[@class='score-time ']/a[contains(@href, 'matches')]]"
)

我正在尝试在//div[@class='match-card match-hour'] 中收集这些值:

但仅当//td[@class='score-time ']/a/@href] 中的@href 包含单词matches:

Apollon 0 - 5 Lech Pozan中的示例链接:

https://int.soccerway.com/matches/2020/09/23/europe/uefa-cup/apollon-limassol/kks-lech-poznan/3360423/
请注意,链接中包含单词matches

为什么只有当有这个文本的时候?

因为在本网站的某些页面上出现结果的地方 匹配的位置不包含匹配的链接,仅 那些带有“匹配”一词的人。

【问题讨论】:

  • 值都是FT;这是您的预期输出吗?
  • 不幸的是,我无法理解您对问题的期望输出值。我为此道歉。可以问一下具体情况吗?
  • @JackFleeting 你好,在这个特定页面上,每个人都是FT,但在同一站点的其他页面上,没有。其中一些在'score-time' 中不存在@href,所以我只需要在有链接到'score-time' 的链接(@href)并且此链接在您的文本中包含'matches' 时进行过滤。跨度>
  • @Tanaike 我更新了问题以试图澄清我需要什么。
  • 感谢您的回复。根据您的回复和补充信息,我提出了一个修改后的公式作为答案。你能确认一下吗?在这种情况下,将检索 35 个FT 值。如果我误解了您的目标并且这不是您期望的结果,我深表歉意。

标签: google-sheets google-sheets-formula


【解决方案1】:

您要检索的 HTML 具有如下结构。

<td class="day ">
  <div class="match-card match-hour">FT</div>
</td>
<td class="team team-a ">
  <a href="/teams/cyprus/apollon-limassol/518/" class="flag_16 right_16 cyprus_16_right" title="Apollon">Apollon</a>
</td>
<td class="score-time ">
  <a href="/matches/2020/09/23/europe/uefa-cup/apollon-limassol/kks-lech-poznan/3360423/">
    <span class="extra_time_score">0 - 5</span>
  </a>
</td>

在这种情况下,我认为 xpath 可能是//div[@class='match-card match-hour' and ../../td[@class='score-time ']/a[contains(@href, 'matches')]]。那么下面的修改公式呢?

修改公式:

=IMPORTXML(
"https://int.soccerway.com/international/europe/uefa-cup/20202021/3rd-qualifying-round/r59325/",
"//div[@class='match-card match-hour' and ../../td[@class='score-time ']/a[contains(@href, 'matches')]]"
)
  • 在此 HTML 中,//div[../../td[@class='score-time ']/a[contains(@href, 'matches')]] 和 //div[../../td[@class='score-time ']] 也可以用作 xpath。

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2018-03-28
    • 2016-02-07
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 2017-09-23
    相关资源
    最近更新 更多