【问题标题】:How to grab text from Kick Starter using XPath in Google Sheets如何在 Google Sheets 中使用 XPath 从 Kick Starter 抓取文本
【发布时间】:2018-04-29 23:58:46
【问题描述】:

我正在尝试从 Kick Starter 中提取位置数据以添加到我现有的数据集中。

目前我正在使用 Google Sheets 和 XPath 来抓取各种元素,但我只是在处理位置的文本元素时遇到了问题。

它看起来像下面这样:

A1 = https://www.kickstarter.com/projects/1201626825/tori-scott-live-at-the-edinburgh-fringe-festival?ref=home_new_and_noteworthy
A2 = //a[@class="nowrap navy-700 flex items-center medium type-12"]/text()
IMPORTXML(A1, $A$2)

奇怪的是,无论我是否放入 text() 元素,我都会收到 Imported content is empty 错误。

我也有:

  • 成功抓取整个列表元素(推广状态、类别、位置)
  • 尝试提取具有空内容错误的确切位置

【问题讨论】:

  • 我的回答有用吗?你能告诉我吗?这对我学习也很有用。如果这样可行,与您有相同问题的其他人也可以将您的问题作为可以解决的问题。

标签: xml xpath google-sheets


【解决方案1】:

这个答案怎么样?我认为您的情况有几个答案。因此,请将此视为其中之一。

第 1 部分:

=INDEX(IMPORTXML(A1, "//div[@class='block-lg hide']//div[@class='NS_projects__badges mb3']//div[@class='border-top border-bottom border-top-none-md border-none-lg nested-full-width-xs nested-full-width-sm nested-full-width-md mb4 mb5-sm mb0-md']//div[@class='grid-row']//div[@class='col-sm-22-24 col-offset-sm-1-24 col-offset-md-0-24']//div[@class='py2 py3-lg flex']//div[@class='flex items-center auto-scroll-x']"), 6)

或

=INDEX(IMPORTXML(A1, "//div[@class='block-lg hide']//div//div//div//div//div//div"), 6)

第 2 部分:

=INDEX(IMPORTXML(A1, "//div[@class='col-full']//div[@class='NS_projects__badges mb3']//div[@class='border-top border-bottom border-top-none-md border-none-lg nested-full-width-xs nested-full-width-sm nested-full-width-md mb4 mb5-sm mb0-md']//div[@class='grid-row']//div[@class='col-sm-22-24 col-offset-sm-1-24 col-offset-md-0-24']//div[@class='py2 py3-lg flex']//div[@class='flex items-center auto-scroll-x']"), 6)

或

=INDEX(IMPORTXML(A1, "//div[@class='col-full']//div//div//div//div//div//div"), 6)

结果:

Edinburgh, UK

注意:

  • 在 HTML 中有两部分 @class="nowrap navy-700 flex items-center medium type-12"。我不确定你想要的部分。所以在这里,我想提出 2 个部分。
  • 假设https://www.kickstarter.com/projects/1201626825/tori-scott-live-at-the-edinburgh-fringe-festival?ref=home_new_and_noteworthy在单元格A1中。

如果我误解了你的问题,我很抱歉。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 2022-01-22
    • 2018-01-02
    • 1970-01-01
    • 2013-11-14
    • 2020-12-29
    相关资源
    最近更新 更多