Forums

Error when trying to run selenium python script?

Hello - i try to run a python-script on pythonanywhere which is using headless-mode -

It tried it with the following code:

  os.environ['WDM_LOG'] = '0' 
  options = Options()
  options.add_argument('--headless=new')  
  options.add_argument("start-maximized")
  options.add_experimental_option("prefs", {"profile.default_content_setting_values.notifications": 1})    
  options.add_experimental_option("excludeSwitches", ["enable-automation"])
  options.add_experimental_option('excludeSwitches', ['enable-logging'])
  options.add_experimental_option('useAutomationExtension', False)
  options.add_argument('--disable-blink-features=AutomationControlled') 
  srv=Service()
  driver = webdriver.Chrome (service=srv, options=options)

But i geht the following error:

Checking for new adds at 2023-09-10 13:26:16.460418 
Traceback (most recent call last):
  File "/home/Rapid1898/collGumtree.py", line 78, in <module>
    driver = webdriver.Chrome (service=srv, options=options)    
  File "/home/Rapid1898/sel/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/Rapid1898/sel/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "/home/Rapid1898/sel/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 269, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/Rapid1898/sel/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 360, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/Rapid1898/sel/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 425, in execute
    self.error_handler.check_response(response)
  File "/home/Rapid1898/sel/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
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.)
Stacktrace:

How is it possible to run a selenium script on pythonanywhere?

It's certainly possible, though there are a couple of extra command-line flags you'll need -- see this help page for details.

However, I see that you're using a free account -- free accounts on PythonAnywhere have restricted Internet access, and can only access this sites on our allowlist. That list is limited to sites offering an official public API, so you won't be able to to general web-scraping with Selenium without upgrading to a paid account.

Thx a lot -

What does this sytem images mean in the description you sent? fishnchips 4.1.3 2022-09-06 glastonbury 4.4.3 2022-09-06 haggis 4.7.2 2022-12-23

Are this the names of the version from Selenium? (never heard from something like this) Or is this something different?

Yes, those are confirmed Selenium versions to be working on different system images. Your account is on the "haggis" system image.

Thx - where can i see on which system-image my account is?

Go to the Account page and switch to the "System image" tab. See this help page for more details about changing system images.

Thx again - works now fine with selenium 4.7.2