tiktokAutoPublisher/get_cookies.py

39 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
def get_douyin_cookies():
# 初始化浏览器
print("正在启动浏览器...")
driver = webdriver.Safari() # 也可以使用Chrome或Firefox
# 打开抖音登录页面
driver.get("https://www.douyin.com/")
driver.maximize_window()
print("请在浏览器中手动登录抖音...")
print("登录成功后请按Enter键继续...")
input()
# 等待登录完成,可以手动检查是否登录成功
time.sleep(2)
# 获取cookies
cookies = driver.get_cookies()
# 保存cookies
cookies_file = "douyin_cookies.json"
with open(cookies_file, "w") as f:
json.dump(cookies, f)
print(f"Cookies已保存到 {cookies_file}")
# 退出浏览器
driver.quit()
return cookies_file
if __name__ == "__main__":
cookies_file = get_douyin_cookies()
print(f"您可以在douyin_publisher.py中使用此cookies文件: {cookies_file}")