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
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.
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.
@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?
Hey there, MiloCat 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.
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