Python+selenium Using cookies

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.