Home > Software engineering >  Selenium webdriver crashing on heroku
Selenium webdriver crashing on heroku

Time:08-01

I need to run a full chrome browser on heroku in order to scrape data. This browser cannot be headless or it does not get the data I desire. Why does it crash with the following error when I try to initialize the driver?

Error: DevToolsActivePort file doesn't exist

def getDriver():
    try:
        chrome_options = webdriver.ChromeOptions()
        chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
        # chrome_options.add_argument("--headless")
        chrome_options.add_argument("start-maximized")
        chrome_options.add_argument("--window-size=1920,1080")
        chrome_options.add_argument("--disable-dev-shm-usage")
        chrome_options.add_argument("--no-sandbox")
        chrome_options.add_argument('--user-agent="Mozilla/5.0 (Windows Phone 10.0 Android 4.2.1 Microsoft Lumia 640 XL LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166"') 
        chrome_options.add_argument("--disable-dev-shm-usage")

        driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=chrome_options)
        return driver    
     except Exception:
        traceback.print_exc()
        print(Exception)

it works with the --headless option but I cannot use that because then the data I need is missing.

CodePudding user response:

The dynamic content was still being loaded headless which is the only way to run on heroku, my issue was an Ad blocker. which I have employed a ssas to go around and get the html content.

  • Related