Skip to content

Instantly share code, notes, and snippets.

@KaushikShresth07
Created September 9, 2023 11:22
Show Gist options
  • Select an option

  • Save KaushikShresth07/18a8be424b499b31a0f45449ce39157b to your computer and use it in GitHub Desktop.

Select an option

Save KaushikShresth07/18a8be424b499b31a0f45449ce39157b to your computer and use it in GitHub Desktop.
XPaths are Given Here :-
1 - /html/body/div[1]/div/div/main/article/div/div/div/div/div/div/div[2]/div/div/div[2]/div/textarea
2 - /html/body/div[1]/div/div/main/article/div/div/div/div/div/div/div[2]/div/div/div[2]/button/span
3 - /html/body/div[1]/div/div/main/article/div/div/div/div/div/div/div[2]/div/div/div[1]/div[{Data}]/span[2]
# Setting Up The Driver & Opening The Website :-
chrome_driver_path = 'chromedriver.exe'
chrome_options = Options()
chrome_options.headless = True
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_argument('--log-level=3')
driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
driver.maximize_window()
driver.get(Link)
# File Operations :- Writing, Reading
def FileReader():
File = open("Chatnumber.txt","r")
Data = File.read()
File.close()
return Data
def FileWriter(Data):
File = open("Chatnumber.txt","w")
File.write(Data)
File.close()
# Sending The Query To The Website :-
def ChatGPTBrain(Query):
Query = str(Query)
driver.find_element(by=By.XPATH,value="").send_keys(Query)
sleep(1)
driver.find_element(by=By.XPATH,value="").click()
Data = str(FileReader())
# Getting Replies :-
while True:
sleep(0.5)
try:
AnswerXpath = f""
Answer = driver.find_element(by=By.XPATH,value=AnswerXpath).is_displayed()
if str(Answer)=="True":
break
except:
pass
AnswerXpath = f""
Answer = driver.find_element(by=By.XPATH,value=AnswerXpath).text
NewData = int(Data) + 2
FileWriter(Data=str(NewData))
return Answer
# Rest Of The Code
print("Starting The GPT4-Model.")
FileWriter(Data='3')
while True:
try:
Query = input("Enter Your Query : ")
print(ChatGPTBrain(Query=Query))
except:
pass
@AgrajSharma99

Copy link
Copy Markdown

didn't work . after running the code several times that gpt4 login website gets open again and again

@omkar1312-dev

Copy link
Copy Markdown

Getting same problem like @AgrajSharma99 its open gpt webpage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment