Since you mentioned you want to use the built-in IMPORT*
functions, I will answer from that perspective.
As with most Sheets-based scraping, it depends on the site. The two sites you have given behave very differently. Let's examine them separately:
1: Yahoo Finance - Possible
We view source and see that 0.82 is located in a table. This lets us use IMPORTHTML
:
=INDEX(
SPLIT(
VLOOKUP(
"Forward Dividend & Yield",
IMPORTHTML("https://finance.yahoo.com/quote/AAPL?p=AAPL", "table", 2),
2,
),
" "
),
1
)
- Import table data
- Get the dividend row
- Extract the dividend yield value.
2: Street Insider - Not Possible
You might think that since the View Source lets us see the table in the browser, we should be able to use IMPORTHTML()
again. Sadly this is not the case. The server-side seems to detect that you're not using a browser to access the .php
, and it will display an empty page. Google sheets uses a different user agent from your own browser.
The only thing I can recommend if you need to use the IMPORT*
functions is that you find a different site to pull the data from.