Chatgpt python bot boiler code

yellowcat

Regular Member
Joined
Aug 27, 2015
Messages
404
Reaction score
297
chatgpt_bot.py
Python:
import undetected_chromedriver as uc
import time
import pickle
from selenium.webdriver.common.keys import Keys
from colorama import Fore, Style, init
# Define a custom user agent


class chatgptBot():
    def __init__(self):
        print ("beep boop chatgpt bot skelly")
        
    def doLogin(self,username=None,password=None):
        my_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
        
        # Set up Chrome options
        options = uc.ChromeOptions()
        options.headless = False
        options.add_argument(f"user-agent={my_user_agent}")
        
        # Initialize Chrome Webdriver with the specified options
        self.driver = uc.Chrome(options=options)
        
        # Make a request to your target website.
        self.driver.get("https://chat.openai.com/")
        
        self.driver.find_element("xpath","""//*[@id="__next"]/div[1]/div[2]/div[1]/div/div/button[1]""").click()
        time.sleep(3)
        self.driver.find_element("xpath","""//*[@id="username"]""").send_keys(username)
        
        time.sleep(.3)
        self.driver.find_element("xpath",'/html/body/div/main/section/div/div/div/div[1]/div/form/div[2]/button').click()
        
        time.sleep(3)
        self.driver.find_element("xpath",'//*[@id="password"]').send_keys(password)
        time.sleep(3)
        self.driver.find_element("xpath",'/html/body/div[1]/main/section/div/div/div/form/div[3]/button').click()
        
        print ("waiting for login...")
        input("<<press enter>>")



    def send_message(self,msg):
        time.sleep(5)
        self.driver.find_element("xpath",'//*[@id="prompt-textarea"]  ').send_keys(msg)
        time.sleep(3)
        self.driver.find_element("xpath",'//*[@id="prompt-textarea"]  ').send_keys(Keys.ENTER)
        time.sleep(3)




    def read_all_messages(self):
        logz = self.driver.find_elements("class name", "markdown")
        print(Fore.GREEN + "Number of elements found:", len(logz))
        print(Style.RESET_ALL)

        for log in logz:
            print(Fore.YELLOW + '==========================')
            print(Fore.WHITE + log.text)
            print(Style.RESET_ALL)

    def debug_read_all_messages(self):
        while True:
            logz = self.driver.find_elements("class name", "markdown")
            print(Fore.GREEN + "Number of elements found:", len(logz))
            print(Style.RESET_ALL)

            for log in logz:
                print(Fore.YELLOW + '==========================')
                print(Fore.WHITE + log.text)
                print(Style.RESET_ALL)
                input('Press Enter to continue...')

bot.py
Python:
from chatgpt_bot import chatgptBot


username = ""
password = ""
gptbot = chatgptBot()

msg = "hello world"

gptbot.doLogin(username,password)

gptbot.send_message(msg)

gptbot.read_all_messages()
input(">>")
 
Simple bot to enter in a message and read responses.
Very barebones working on windows chrome Version 118

Usage: after you login there may be a captcha for you to solve (Hence why i added input() )
After logging in just click any pop ups
 
It would be much better if you could integrate captcha solver.
 
1697160876692.png


Seems like i got ip restricted after logging in a few times using same account. was able to relogin using vpn tho
 
View attachment 291257

Seems like i got ip restricted after logging in a few times using same account. was able to relogin using vpn tho
Did you bomb them of login attempts or they restricted you because they can tell it's not a "regular" browser?

I'm new to this topic and trying to gain a basic understanding as I take my first steps. Thanks
 
Did you bomb them of login attempts or they restricted you because they can tell it's not a "regular" browser?

I'm new to this topic and trying to gain a basic understanding as I take my first steps. Thanks
was able to get in simply reusing cookies from a previous login session. i was only ip banned so swapped over to a vpn logged in saved cookies n just used those to reload session. it worked was able to generate a few hundred articles through this.
 
was able to get in simply reusing cookies from a previous login session. i was only ip banned so swapped over to a vpn logged in saved cookies n just used those to reload session. it worked was able to generate a few hundred articles through this.
Thanks for taking the time to reply. Saved the trick in my notes for future reference ;)
 
Back
Top