How can I fix the errors in this code? (Answered!)

Question:
How can I fix these errors?
Repl link:
https://replit.com/@MiloCat/OpenAIScrape?v=1

from selenium import webdriver
import requests
from bs4 import BeautifulSoup
webpage = r"chat.openai.com" # edit me
userprompt = input("Enter prompt here:\n")
searchterm = userprompt # edit me

driver = webdriver.Chrome()
driver.get(webpage)

sbox = driver.find_element_by_class_name("textarea")
sbox.send_keys(searchterm)

submit = driver.find_element_by_class_name("button")
submit.click()

text = driver.find_element_by_class_name("p")
print("text")
Errors:
Traceback (most recent call last):
  File "main.py", line 8, in <module>
    driver = webdriver.Chrome()
  File "/home/runner/OpenAIScrape/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    super().__init__(
  File "/home/runner/OpenAIScrape/venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
    self.service.start()
  File "/home/runner/OpenAIScrape/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 106, in start
    self.assert_process_still_running()
  File "/home/runner/OpenAIScrape/venv/lib/python3.8/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 chromedriver unexpectedly exited. Status code was: 127

Hello @MiloCat

The error message you provided suggests that the Chrome driver (chromedriver) is not running. This is likely due to the fact that the Chrome driver executable is not in the system’s PATH environment variable, or it is not installed on the system.

You can fix this issue by:

  • Downloading the Chrome driver executable from “Downloads - ChromeDriver - WebDriver for Chrome” and adding its path to PATH environment variable.

  • Or installing chrome driver via package manager like apt-get, yum or brew (on mac)

After that you need to give the path of chrome driver to the driver variable by using webdriver.Chrome(path_of_chrome_driver)

Also, the URL you are trying to scrape is not a website, it’s the endpoint for OpenAI’s GPT-3 model. If you want to scrape data from a website, you should use a valid URL.

let me know if this works

hope it helps ! :slight_smile:

1 Like

@bil0009 I have chrome installed on my computer (Chrome OS). I am trying to run this in replit.com. Also I am using chat.openai.com because I want to access ChatGPT through code because I do not have an API key. The textarea input is where you would normally type text and the p is because ChatGPT responds in a <p>. Also how would I add this?

1 Like

Hey there, MiloCat :slight_smile: it’s bigminiboss! While I’m not very good at selenium, I would like to point out that using proxies are against the ToS, I believe.

  1. Use the Service to create a proxy with the purpose of circumventing any firewall or other access control measure;

This would not be true were you not accessing chatgpt which I believe does not have an API. Instead, try using openAi’s Davinci API or some other model :stuck_out_tongue:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.