做一些自动化的时候, 常常要求登录才能做操作,自动化登录通常会触发人机校验(滑动验证码之类的)
首先需要准备已登录的抖音, 找到cookie
中的sessionid
, 但是这个是有时间限定的(过期后就登录不了, 但是这个时间挺长的, 我也不知道具体多长, 反正我还剩一个多月才过期)
import time
from selenium import webdriver
user_url = "https://www.douyin.com/user/self"
driver = webdriver.Chrome()
def login_by_cookie():
driver.get(user_url)
time.sleep(1)
cookies = {
'name': 'sessionid',
'value': 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
}
driver.add_cookie(cookie_dict=cookies)
driver.refresh()
def main():
login_by_cookie()
while True:
time.sleep(10)
if __name__ == '__main__':
main()
但是有时候DY动不动就会弹出一个人机校验验证码…
2.33 Okc:/ 12/01 F@h.oD 使用cookie自动登录DY # selenium # 自动化 # cookie https://v.douyin.com/iL9YsXwF/ 复制此链接,打开Dou音搜索,直接观看视频!