业务合作请联系:13958075150
【1】首次登录使用selenium登录并将cookies存为文件,实现免密登录,并便于后期维护cookie。
# 首次使用selenium登录,并将cookies存为文件
from selenium import webdriver
import time
import json
br = webdriver.Chrome()
br.get("https://mp.toutiao.com")
# 点击登陆按钮
login = br.find_element_by_css_selector('body > div > div.carousel > div.page.page-1 > div > img.i3')
login.click()
time.sleep(3)
# 点击手机密码登录按钮
phone_login_button = br.find_element_by_css_selector('#login-type-account')
phone_login_button.click()
# 填写手机号
user_name = br.find_element_by_id('user-name')
user_name.send_keys('您的账号')
# 填写密码
password_input = br.find_element_by_id('password')
password_input.send_keys('您的密码')
# 登陆
br.find_element_by_id('bytedance-login-submit').click()
time.sleep(5)
cookies = br.get_cookies()
# print(cookies)
with open('/Users/macbookair/Desktop/cookies-2.json', '