This repository has been archived by the owner on Mar 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
39 lines (30 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
import os
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from undetected_chromedriver import Chrome, ChromeOptions
options = ChromeOptions()
# options.add_argument("--proxy-server=socks5:https://127.0.0.1:20170")
# options.add_argument("--headless")
driver = Chrome(options=options)
driver.get('https://chat.openai.com')
username = os.environ.get('USERNAME')
password = os.environ.get('PASSWORD')
wait = WebDriverWait(driver, 60)
wait.until(EC.presence_of_element_located(
(By.CLASS_NAME, 'btn.flex.justify-center.gap-2.btn-primary'))).click()
wait.until(EC.presence_of_element_located(
(By.ID, 'username'))).send_keys(username)
wait.until(EC.presence_of_element_located(
(By.CSS_SELECTOR, 'button[type=submit]'))).click()
wait.until(EC.presence_of_element_located(
(By.ID, 'password'))).send_keys(password)
wait.until(EC.presence_of_element_located(
(By.CSS_SELECTOR, 'button[type=submit]'))).click()
driver.get("https://chat.openai.com/api/auth/session")
plain_text = driver.execute_script("return document.body.innerText")
json_data = json.loads(plain_text)
access_token = json_data["accessToken"]
print(access_token)
driver.quit()