Status code was: 127

Question: how to download Chrome or another browser to use it as an emulator for web requests.

from selenium.webdriver.common.by import By
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())

driver.get('http://www.yahoo.com')
assert 'Yahoo' in driver.title

elem = driver.find_element(By.NAME, 'p')  # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)

driver.quit()

Yahoo is just as an example.
Error:

[WDM] - Downloading: 100%|████| 6.83M/6.83M [00:00<00:00, 66.2MB/s]
main.py:102: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
Traceback (most recent call last):
  File "main.py", line 102, in <module>
    driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
  File "/home/runner/Web-request-01v/venv/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 80, in __init__
    super().__init__(
  File "/home/runner/Web-request-01v/venv/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 101, in __init__
    self.service.start()
  File "/home/runner/Web-request-01v/venv/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 106, in start
    self.assert_process_still_running()
  File "/home/runner/Web-request-01v/venv/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 119, in assert_process_still_running
    raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
selenium.common.exceptions.WebDriverException: Message: Service /home/runner/.wdm/drivers/chromedriver/linux64/111.0.5563/chromedriver unexpectedly exited. Status code was: 127

I googled and tried some ways to do it, however nothing helped.
I’m not saying that I did everything right, so I will appreciate your help.

I am not sure, but I dont think selenium is supported on Replit because selenium uses Google Chrome to do everything and as I know, Google Chrome isn’t installed in Repls.
You can instead try the requests and bs4 (BeautifulSoup4) modules, there is a lot of tutorials online like on the great GeeksForGeeks website.
Here is the code with requests and bs4 to get page title:

# Be sure to install packages `requests` and `bs4` !
import requests, bs4

# Set custom headers because some sites refuse access of some bots like this one
headers = {"User-Agent": "mozilla/5.0 (windows; u; windows nt 5.1) applewebkit/538.0.1 (khtml, like gecko) chrome/14.0.878.0 safari/538.0.1"}

# Send the request to the Yahoo site
r = requests.get("https://yahoo.com", headers=headers)

# Create a BeautifulSoup4 object
soup = bs4.BeautifulSoup(r.text, "html.parser")

# Prints the page title
print(soup.find('title').string)

Hope it helped !

1 Like

Add chromedriver via Nix: run in Shell:

sed -i 's/];/  pkgs.chromedriver\n  &/' replit.nix

Then, Ctrl\ in Console, then run your repl

3 Likes

Cool ! I did not knew that Nix (the OS that Replit uses) provides the Chrome Driver. Good to know !

BTW it seems that I missunderstanded what the code should do, so my answer isn’t a really good solution. This is because I never really used selenium or the Chrome driver.