jonesmf
jonesmf

Reputation: 21

ImpoortXML Formula in Google Sheets

I am trying to write an XML formula in Google Sheets that scrapes the text after 'Dividend Yield'

=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]/span[1]

Upvotes: 1

Views: 201

Answers (2)

Mike Steelson
Mike Steelson

Reputation: 15318

You can retrieve the complete table of values with xpath =

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

And then retrieve de Dividend yield for instance by

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

You can in this way define Dividend Yield as a parameter. enter image description here

Upvotes: 1

player0
player0

Reputation: 1

try:

=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]")

or shorter:

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

enter image description here

Upvotes: 1

Related Questions