Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scrape the yahoo earnings calendar with beautifulsoup

How can I scrape the yahoo earnings calendar to pull out the dates?

This is for python 3.

from bs4 import BeautifulSoup as soup
import urllib

url = 'https://finance.yahoo.com/calendar/earnings?day=2019-06-13&symbol=ibm'

response = urllib.request.urlopen(url)
html = response.read()

page_soup = soup(html,'lxml')
table = page_soup.find('p')
print(table)

the output is "None"

like image 765
bud fox Avatar asked Nov 24 '25 08:11

bud fox


2 Answers

Might be off-topic but since you want to get a table from a webpage, you might consider using pandas which works with two lines:

import pandas as pd
earnings = pd.read_html('https://finance.yahoo.com/calendar/earnings?day=2019-06-13&symbol=ibm')[0]
like image 55
Sebastien D Avatar answered Nov 25 '25 21:11

Sebastien D


Beautiful Soup has some find functions that you can use to inspect the DOM , please refer to the documentation

from bs4 import BeautifulSoup as soup
import urllib.request

url = 'https://finance.yahoo.com/calendar/earnings?day=2019-06-13&symbol=ibm'

response = urllib.request.urlopen(url)
html = response.read()

page_soup = soup(html,'lxml')
table = page_soup.find_all('td')
Dates = []
for something in table:
    try:
        if something['aria-label'] == "Earnings Date":
            Dates.append(something.text)
    except:
        print('')

print(Dates)
like image 31
Aness Avatar answered Nov 25 '25 21:11

Aness



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!