如題,最近在使用 selenium 碰到無法維持登入的問題,
但 selenium login 後重新 get ithelp 的其他網址時無法維持登入狀態,
有試過添加 cookies 進去再重新 get 一次還是無法維持,
想請教版上大神
import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
account = ""
password = ""
account_css = "input#account"
password_css = "input#password"
enter_css = "button.btn.btn-agree.btn-margin"
driver = Chrome(ChromeDriverManager().install())
driver.get("https://member.ithome.com.tw/login")
driver.find_element(By.TAG_NAME, account_css).send_keys(account)
driver.find_element(By.TAG_NAME, password_css).send_keys(password)
driver.find_element(By.TAG_NAME, enter_css).click()
time.sleep(5)
_cookies = driver.get_cookies()
print(_cookies)
for _cookie in _cookies:
driver.add_cookie(_cookie)
driver.get("https://ithelp.ithome.com.tw/")
time.sleep(5)