Cookie kann nicht zur Website in Selenium hinzugefügt werdenPython

Python-Programme
Anonymous
 Cookie kann nicht zur Website in Selenium hinzugefügt werden

Post by Anonymous »

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import json
import time

service = Service(executable_path=f"chromedriver.exe",
log_path=f"seleniumlog.txt")
selenium_options = Options()
selenium_options.add_argument("--disable-blink-features=AutomationControlled")
selenium_options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36")
selenium_options.add_experimental_option("excludeSwitches", ["enable-automation"])
selenium_options.add_experimental_option('useAutomationExtension', False)
chrome_driver = webdriver.Chrome(service=service, options=selenium_options)
chrome_driver.get("https://www.tiktok.com/login")

time.sleep(5)

cookie = {
'domain': '.tiktok.com',
'expiry': 1734578412,
'httpOnly': True,
'name': 'sessionid',
'path': '/',
'secure': True,
'value': 'abc123'
}

# Step 2: Load cookies
with open("flamencocookies.json", "r") as f:
cookies = json.load(f)

try:
chrome_driver.add_cookie(cookie)
except Exception as e:
print("Could not add cookie")

print(chrome_driver.get_cookies())
< /code>
Ich testet nur Selenium und wählte Tiktok.com aus, um es zu testen. Im obigen Code kann ich das Cookie jedoch nicht zur Browser -Sitzung hinzufügen. Das Cookie -Format scheint korrekt zu sein, ich bekomme keine Ausnahme, aber es ist auch nicht zur Browser -Sitzung hinzugefügt. Weiß jemand warum? Könnte es etwas mit den Switches zu tun haben, die ich dem Browser hinzugefügt habe?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post