Search code examples
pythonselenium-webdriverweb-scrapingwebdriverscreen-scraping

How to properly load website using selenium in python


I'm trying to use selenium to open this link using the code below, but it seems to open just a very raw form of the website, with which I'm not managing to interact properly with the buttons.

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(driver_path), options=options)
driver.get("https://aeromexico.com/es-mx")

wrong_result

What I wanted was for the page to load fully just as it does when I open it manually via Chrome, as the image below:

desired_result

What am I doing wrong here?


Solution

  • Root cause of the issue: The website you are trying to access using selenium is detecting the automation bot, and it is not allowing selenium to access the site. Hence you see the raw form of the website.

    Solution: Download and import the undetected chrome driver library into your project and use it. Once you import the library try the code as below:

    import undetected_chromedriver as uc
    
    driver = uc.Chrome()
    driver.maximize_window()
    driver.get("https://aeromexico.com/es-mx")
    

    Result:

    enter image description here

    Refer below link for more info about undetected chrome driver:

    https://www.zenrows.com/blog/undetected-chromedriver#how-to