diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd19c04 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.py +__pycache__ \ No newline at end of file diff --git a/options.py b/options.py index 393b050..7c4287a 100644 --- a/options.py +++ b/options.py @@ -1,15 +1,16 @@ from bs4 import BeautifulSoup -import urllib.request from config import API_KEY from alpha_vantage.timeseries import TimeSeries import json import datetime +import requests def getEarningsHistoryHTML(stock): - fp = urllib.request.urlopen("https://www.nasdaq.com/earnings/report/{}".format(stock)) - byteArr = fp.read() + headers = {'User-Agent': 'Mozilla/5.0'} + s = "https://www.nasdaq.com/market-activity/stocks/{}/earnings".format(stock) + fp = requests.get(s, headers=headers) + byteArr = fp.content html = byteArr.decode("utf8") - fp.close() return html def getDate(quarterReport): @@ -19,6 +20,7 @@ def getPastEarningsDates(stock): pastEarningsDates = [] soup = BeautifulSoup(getEarningsHistoryHTML(stock), 'html.parser') table = soup.table.find_all('tr') + print(table) for i in range(1, len(table)): quarterReport = table[i] date = getDate(quarterReport)