54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from selenium import webdriver
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.common.keys import Keys
|
|
from selenium.webdriver.chrome.options import Options
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
import time
|
|
import pickle
|
|
|
|
def save_cookies(driver, path):
|
|
with open(path, 'wb') as file:
|
|
pickle.dump(driver.get_cookies(), file)
|
|
|
|
def generate_cookies(email, password):
|
|
cookie_path = r'x:\substack\cookies.pkl'
|
|
|
|
|
|
chrome_options = Options()
|
|
|
|
driver = webdriver.Chrome(options=chrome_options)
|
|
driver.get('https://substack.com/sign-in')
|
|
|
|
wait = WebDriverWait(driver, 10)
|
|
|
|
try:
|
|
login_with_password_button = wait.until(
|
|
EC.element_to_be_clickable((By.LINK_TEXT, 'Sign in with password'))
|
|
)
|
|
login_with_password_button.click()
|
|
|
|
time.sleep(2)
|
|
|
|
email_field = driver.find_element(By.NAME, 'email')
|
|
email_field.send_keys(email)
|
|
|
|
password_field = driver.find_element(By.NAME, 'password')
|
|
password_field.send_keys(password)
|
|
|
|
password_field.send_keys(Keys.RETURN)
|
|
|
|
save_cookies(driver, cookie_path)
|
|
print("Cookies saved successfully.")
|
|
except Exception as e:
|
|
print("An error occurred during login.", e)
|
|
|
|
driver.quit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
email = "gael.honorez@gmail.com"
|
|
password = "f3PaTGedjFc2gkr1ypi5"
|
|
generate_cookies(email, password)
|