### selenium登录cnblogs
```python
'''
# 1 打开cnblogs,点进登录页面,输入用户名密码,点登录(可能会出现验证码)--》手动操作
# 2 登录成功后----》拿到cookie---》保存到本地---》关闭浏览器
# 3 开启selenium,打开浏览器---》把本地的cookie写入到当前浏览器中----》当前浏览器就是登录状态
'''
# 先登录
bro = webdriver.Chrome()
bro.get('https://www.cnblogs.com/')
bro.implicitly_wait(10)
bro.maximize_window()
login_name = bro.find_element(By.CSS_SELECTOR, '#navbar_login_status > a:nth-child(7)')
login_name.click()
login = bro.find_element(By.CSS_SELECTOR, '#mat-tab-label-0-0 > div')
login.click()
username = bro.find_element(By.CSS_SELECTOR, "#mat-input-0")
password = bro.find_element(By.CSS_SELECTOR, "#mat-input-1")
username.send_keys('@qq.com')
password.send_keys('%')
send = bro.find_element(By.CSS_SELECTOR,
'body > app-root > app-sign-in-layout > div > div > app-sign-in > app-content-container > div > div > div > form > div > button > span.mat-button-wrapper')
send.click()
input('')
time.sleep(3)
cookie = bro.get_cookies()
with open('cnblogs.json', 'w', encoding='utf-8') as f:
json.dump(cookie, f)
time.sleep(2)
bro.close()
再次打开
bro=webdriver.Chrome()
bro.get('https://www.cnblogs.com/')
bro.implicitly_wait(10)
bro.maximize_window()
time.sleep(3)
with open('./cnblogs.json','r',encoding='utf-8') as f:
cookie=json.load(f)
for item in cookie:
bro.add_cookie(item)
bro.refresh()#刷新页面
time.sleep(3)
bro.close()
标签:cnblogs,登录,selenium,SELECTOR,bro,cookie,div
From: https://www.cnblogs.com/liyuanxiangls/p/17545592.html