使用cookie自动登录DY,, 避免人机校验

发布时间:2024年01月22日

做一些自动化的时候, 常常要求登录才能做操作,自动化登录通常会触发人机校验(滑动验证码之类的)

首先需要准备已登录的抖音, 找到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音搜索,直接观看视频!

文章来源:https://blog.csdn.net/qq_50969362/article/details/135746813
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。