Add a cookie
1. You need to add two cookies here, one is. Cnblogscookie, the other one is. Cnblogs.AspNetCore.Cookies.
2. The page I opened here is the homepage of the blog: Http://www.cnblogs.com/yoyoketang, which did not enter the login page.
3. After adding a cookie, refresh the page, and the next is the time to witness the miracle.
2.20.5 Reference Code:
# Coding:utf-8
From selenium import Webdriver
Import Time Driver = Webdriver. Firefox ()
Driver.get ("Http://www.cnblogs.com/yoyoketang")
# # Add Cookie C1 = {u ' domain ': U '. cnblogs.com ', U ' name ': U '. Cnblogscookie ', U ' value ': U ' xxxx ', u ' expiry ': 1491887887, U ' path ': U '/', U ' httponly ': True, U ' secure ': False}
C2 = {u ' domain ': U '. cnblogs.com ', U ' name ': U '. Cnblogs.AspNetCore.Cookies ', U ' value ': U ' xxxx ', u ' expiry ': 1491887887, U ' path ': U '/', U ' httponly ': True, U ' secure ': False} driver.add_cookie (C1)
# Add 2 values
Driver.add_cookie (C2)
Time.sleep (3)
# Refresh the next page and witness the miracle.
Driver.refresh ()
There are a few points to note:
1. Check the next automatic login button when you log in.
2.add_cookie () only adds name and value, and the login for the blog Park is unsuccessful.
3. This method is not suitable for all websites, generally like the blog park This remember the login status will be suitable
Python+selenium Using cookies