0
votes

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]

2

2 Answers

0
votes

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

0
votes

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 * where Col1='Dividend Yield' ")

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