What is wrong with my code? Is there no way around this? Not doing anything nefarious, just trying to get the obtain the “Press Releases” link for each quarter on the Apple Investor Relations Website.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import undetected_chromedriver as uc
def get_page_html(url):
# Initialize undetected chromedriver
options = uc.ChromeOptions()
options.headless = True # Run Chrome in headless mode
driver = uc.Chrome(options=options)
try:
driver.get(url)
page_html = driver.page_source
soup = BeautifulSoup(page_html, 'html.parser')
formatted_html = soup.prettify()
return formatted_html
finally:
driver.quit()
if __name__ == "__main__":
url = 'https://investor.apple.com/investor-relations/default.aspx'
html = get_page_html(url)
print(html)