Search code examples
pythonpython-3.xweb-scrapingyahoo-finance

python web-scraping yahoo finance


Since Yahoo finance updated their website. some tables seem to be created dynamically and not actually stored in the HTML (I used to get this information using BeautifulSoup, urllib but this won't work anymore). I am after the Analyst tables for example ADP specifically the Earnings Estimates for Year Ago EPS (Current Year Column). You cannot get this information from the API.

I found this link which works well for the Analyst Recommendations Trends. does anyone know how to do something similar for the main table on this page? (LINK: python lxml etree applet information from yahoo )

I tried to follow the steps taken but frankly its beyond me. returning the whole table is all I need I can pick out bits from there. cheers


Solution

  • In order to get that data, you need to open Chrome DevTools and select Network tab with XHR filter. If you click on ADP request you can see link in RequestUrl.

    enter image description here

    You can use Requests library for making a request and parsing json response from the site.

    import requests
    from pprint import pprint
    
    url = 'https://query1.finance.yahoo.com/v10/finance/quoteSummary/ADP?formatted=true&crumb=ILlIC9tOoXt&lang=en-US&region=US&modules=upgradeDowngradeHistory%2CrecommendationTrend%2CfinancialData%2CearningsHistory%2CearningsTrend%2CindustryTrend%2CindexTrend%2CsectorTrend&corsDomain=finance.yahoo.com'
    r = requests.get(url).json()
    pprint(r)