I have had success with implementing the following solution for annual data. Code is from the answer below.
R: web scraping yahoo.finance after 2019 change
How