Check out Kite (free AI Coding Assistant) → Link



Buy Me a Coffee? Your support is much appreciated!

PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn

Source Code:

from pprint import pprint
import datetime
import requests # pip install requests
from bs4 import BeautifulSoup # pip install beautifulsoup4
import pandas as pd # pip install pandas

url = "https://www.marketwatch.com/tools/ipo-calendar"
headers= {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0'}

response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')

tabPanes_body = soup.find('div', 'element__body j-tabPanes')
tabPanes = tabPanes_body.find_all('div', 'tab__pane')

dfs = {}
current_datetime = datetime.datetime.now().strftime('%m-%d-%y %H_%M_%S')
xlsxwriter = pd.ExcelWriter('IPO Calendar ({0}).xlsx'.format(current_datetime))

for tabPane in tabPanes:
    headers = tabPane.find_all('header')
    for indx, header in enumerate(headers):
        tab_name = header.h2.div.contents[0]
        dfs[tab_name] = pd.read_html(str(tabPane.find_all('table', {'class': 'table'})[indx]))[0]
        dfs[tab_name].to_excel(xlsxwriter, sheet_name=tab_name, index=False)

xlsxwriter.save()