Forums

Run Python Script with ChromeDriver - downgraded Selenium

I know, there are already some posts about the topic and I already checked them out:

e.g.: 1) https://help.pythonanywhere.com/pages/selenium/ 2) https://www.pythonanywhere.com/forums/topic/13460/ and several others.

As 2) suggests I downgraded Selenium to the latest version before 4.0.0 (3.141.0) via bash which worked fine.

Then I uploaded the given script from 1) and ran it in a console:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox”)
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)

try:
    browser.get("https://www.google.com")
    print("Page title was '{}'".format(browser.title))
finally:
    browser.quit()

The first (probably minor) issue is a "SyntaxError: EOL while scanning string literal" in line 4. I will probably sort that out at some point but to further simplify the process I reduced the code to the following:

from selenium import webdriver

browser = webdriver.Chrome()

try:
    browser.get("https://www.google.com")
    print("Page title was '{}'".format(browser.title))
finally:
    browser.quit()

Yet, I still get the following error: "selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)"

I'd appreciate some help and since it's my first post on any coding forum I ask for forgiveness in case of any unintended bad manners.

Don't worry, you're being perfectly polite :-)

The first problem, "SyntaxError: EOL while scanning string literal", is due to an error on our help page -- if you look closely, you'll see that the first double-quote on that line in the code in your post is a regular double-quote, but the second is a "smart quote" at an angle. If you replace the second one with a normal ", it should work fine. Thanks for the heads-up about that! I've fixed the help page now.

The reason for the second error message is just that those options are necessary to run Selenium on PythonAnywhere, so if you re-introduce them with the fix I mentioned above (or just copy them from the updated help page) then that will sort that out.

Perfect, thanks a lot for the quick support!!!

No problem, glad to help!