【问题标题】:ImpoortXML Formula in Google SheetsGoogle 表格中的 ImportXML 公式
【发布时间】:2021-09-29 21:43:44
【问题描述】:

我正在尝试在 Google 表格中编写一个 XML 公式,用于在“股息收益率”之后抓取文本

=IMPORTXML("https://www.cnbc.com/quotes/intc", XPATH QUERY)

Xpath://*[@id="MainContentContainer"]/div/div[2]/div[1]/div[5]/div[2]/section/div[1]/ul/li[ 13]/跨度[1]

【问题讨论】:

    标签: xml web-scraping google-sheets google-sheets-formula


    【解决方案1】:

    尝试:

    =IMPORTXML("https://www.cnbc.com/quotes/intc", 
     "/html/body/div[2]/div/div[1]/div[3]/div/div[2]/div[1]/div[5]/div[2]/section/div[1]/ul/li[13]/span[2]")
    

    或更短:

    =IMPORTXML("https://www.cnbc.com/quotes/intc", 
     "//section/div[1]/ul/li[13]/span[2]")
    

    【讨论】:

      【解决方案2】:

      您可以使用 xpath = 检索完整的值表

      //li[@class='Summary-stat']
      

      然后检索de股息收益率例如

      =query(importxml(url,xpath),"select Col2 where Col1='Dividend Yield' ")
      

      您可以通过这种方式将股息收益率定义为参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-30
        相关资源
        最近更新 更多