Giter VIP home page Giter VIP logo

chatgpt_selenium_automation's Introduction

chatgpt_selenium_automation

ChatGPT Automation is a Python project that aims to automate interactions with OpenAI's ChatGPT using Selenium WebDriver. Currently, it requires human interaction for log-in and human verification. It handles launching Chrome, connecting to ChatGPT, sending prompts, and retrieving responses. This tool can be useful for experimenting with ChatGPT or building similar web automation tools.

Prerequisites

  1. Install the library: pip install git+https://github.com/Michelangelo27/chatgpt_selenium_automation.git
  2. Download the appropriate version of chromedriver.exe and save it to a known location on your system.

Example Usage

from chatgpt_selenium_automation.handler import ChatGPTAutomation

# Define the path where the chrome driver is installed on your computer
chrome_driver_path = r"C:\Users\user\Desktop\chromedriver.exe"

# the sintax r'"..."' is required because the space in "Program Files" in the chrome path
chrome_path = r'"C:\Program Files\Google\Chrome\Application\chrome.exe"'

# Create an instance
chatgpt = ChatGPTAutomation(chrome_path, chrome_driver_path)

# Define a prompt and send it to chatgpt
prompt = "What are the benefits of exercise?"
chatgpt.send_prompt_to_chatgpt(prompt)

# Retrieve the last response from ChatGPT
response = chatgpt.return_last_response()
print(response)

# Save the conversation to a text file
file_name = "conversation.txt"
chatgpt.save_conversation(file_name)

# Close the browser and terminate the WebDriver session
chatgpt.quit()

Note

After instantiating the ChatGPTAutomation class, chrome will open up to chatgpt page, it will require you to manually complete the register/ log-in / Human-verification. After that, you must tell the program to continue, in the console type 'y'. After Those steps, the program will be able to continue autonomously.

Note on Changing Tabs or Conversations

Please be aware that changing tabs or switching to another conversation while the script is running might cause errors or lead to the methods being applied to unintended chats. For optimal results and to avoid unintended consequences, it is recommended to avoid to manually interact with the browser (after the log-in/human verification) while the automation script is running.

Note on Errors and Warnings

While running the script, you may see some error messages or warnings in the console, such as:

  • DevTools listening on ws://...
  • INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
  • ERROR: Couldn't read tbsCertificate as SEQUENCE
  • ERROR: Failed parsing Certificate

These messages are related to the underlying libraries or the browser, and you can safely ignore them if the script works as expected. If you encounter any issues with the script, please ensure that you have installed the correct dependencies and are using the correct ChromeDriver version compatible with your Chrome browser.

chatgpt_selenium_automation's People

Contributors

0xrushi avatar matteo-rizzo avatar michelangelo27 avatar shen-qin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

chatgpt_selenium_automation's Issues

ModuleNotFoundError: No module named 'handler'

First i did:

pip install ChatGPTAutomation

then in python the example code.

from handler.chatgpt_selenium_automation import ChatGPTAutomation
chrome_driver_path = r"/Users/ishandutta2007/Documents/chrome-mac-arm64/Google Chrome for Testing.app"
chrome_path = r'"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"'
chatgpt = ChatGPTAutomation(chrome_path, chrome_driver_path)
prompt = "What are the benefits of exercise?"
chatgpt.send_prompt_to_chatgpt(prompt)
response = chatgpt.return_last_response()
file_name = "conversation.txt"
chatgpt.save_conversation(file_name)
chatgpt.quit()

Not full response saved

Hello,
Again great work on the tool - for me it breaks off afters saving maybe half the response? It doesn't wait until chatgpt generated the response until the end.

Something I can do about it?

Can ARM64 use it?

My code is as below, but it seems not work, please help thanks

from chatgpt_selenium_automation.handler import ChatGPTAutomation

# Define the path where the chrome driver is installed on your computer
chrome_driver_path = r"/chromedriver/chromedriver"

# the sintax r'"..."' is required because the space in "Program Files" in the chrome path
chrome_path = r'"/Applications/Google Chrome.app"'

# xattr -d com.apple.quarantine /Users/ethanwu/Documents/GitHub/llm_project/kgis_openai/chromedriver/chromedriver

# Create an instance
chatgpt = ChatGPTAutomation(chrome_path, chrome_driver_path)

# Define a prompt and send it to chatgpt
prompt = "What are the benefits of exercise?"
chatgpt.send_prompt_to_chatgpt(prompt)

# Retrieve the last response from ChatGPT
response = chatgpt.return_last_response()
print(response)

# Save the conversation to a text file
file_name = "conversation.txt"
chatgpt.save_conversation(file_name)

# Close the browser and terminate the WebDriver session
chatgpt.quit()

Some arguments might be outdated

Hi, and thank you for your work!

I tried using the code, but the executable-path argument in webdriver.Chrome within the setup_webdriver function is throwing an error. The following works:

  def setup_webdriver(self, port):
      """  Initializes a Selenium WebDriver instance, connected to an existing Chrome browser
           with remote debugging enabled on the specified port"""

      chrome_options = webdriver.ChromeOptions()
      chrome_options.binary_location = self.chrome_driver_path
      chrome_options.add_experimental_option("debuggerAddress", f"127.0.0.1:{port}")
      driver = webdriver.Chrome(options=chrome_options)
      return driver

Similarly, in the function send_prompt_to_chatgpt, the input box could not be found via XPath using the current expression. The expression //textarea[contains(@id, "prompt-textarea")] fixes the problem.

I will send a pull request with the changes soon, have a good day :)

Stuck at "Continuing with the automation process..."

Hello,
Great article on medium and thanks for the work with the script.
I am not familiar with the Selenium stuff, but I tried to execute the sample code you have provided and am getting stuck at "Continuing with the automation process..."

My chrome browser opens normally and I am logged in.
This is my full log;

You need to manually complete the log-in or the human verification if required.
Enter 'y' if you have completed the log-in or the human verification, or 'n' to check again: y
Continuing with the automation process... 

Please help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.