【问题标题】:Error trying to get page title in google sheets尝试在谷歌表格中获取页面标题时出错
【发布时间】:2023-01-25 22:31:58
【问题描述】:

我全部,你能帮我用正确的 XPath 来选择标签中包含的标题“Quotes to Scrape”的文本,它在标签内,在以下网页 https://quotes.toscrape.com/ 上? 我需要在 google 表格中的 xmlimport 函数上使用这个 xpath,但我不确定 xpath 是否正确 =IMPORTHTML("https://quotes.toscrape.com/","//div[@class='col-md-8']/h1/a") 但我在 google 表格中有错误

我期待在 /h1/a 中获取文本

【问题讨论】:

  • 看起来像一个错字,=IMPORTXML("http://quotes.toscrape.com/","//div[@class='col-md-8']/h1/a") 工作正常。

标签: google-sheets web-scraping


【解决方案1】:

我将此答案作为社区 Wiki 编写,因为该解决方案是由 @margusl 在 cmets 部分提供的,以供社区查看。

该问题与公式的拼写错误有关。有问题的公式是

=IMPORTHTML("https://quotes.toscrape.com/","//div[@class='col-md-8']/h1/a")

但是,IMPORTHTML 不使用 XPath,它使用像 here 提到的“List”或“Table”这样的查询。

因此,要解决此问题,您需要更正拼写错误并使用:

=IMPORTXML("http://quotes.toscrape.com/","//div[@class='col-md-8']/h1/a")

或者您也可以使用:

=IMPORTXML("http://quotes.toscrape.com/","/html/body/div/div[1]/div[1]/h1/a")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多