user1837293
user1837293

Reputation: 1676

How get content from html element in Google spreadsheet?

I can use following code in Google Spreadsheet to retrieve a specific <span> element on that html-document.

=IMPORTXML("https://finance.yahoo.com/quote/NBIX201218C00125000?p=NBIX201218C00125000";"//td[@data-test='PREV_CLOSE-value']/span")

But this returns the error message that the returned content is empty.

content empty

So how do I retrieve the content (in this example the text '17.00') of this HTML-element in the spreadsheet?

span-element

Upvotes: 0

Views: 3084

Answers (2)

E.Wiest
E.Wiest

Reputation: 5915

Use IMPORTFROMWEB addon (number of requests are limited in the free plan) to get this.

YF XPath used :

//td[@data-test='PREV_CLOSE-value']/span

Formula in C5 :

=IMPORTFROMWEB(C1;C2)

Upvotes: 2

wizardofOz
wizardofOz

Reputation: 127

Maybe this is because of the consent manager on Yahoo, that is shown before you get to the actual page.

enter image description here

When I downloaded the page, after checked the consent, put in on my server and use your code in Google Spreadsheets it is working.

enter image description here

Upvotes: 0

Related Questions