Home  >  Article  >  Backend Development  >  Python cookielib module for operating cookies

Python cookielib module for operating cookies

大家讲道理
大家讲道理Original
2016-11-07 10:52:231654browse

Cookielib is a module that automatically handles cookies. If we need to save cookies when using technologies such as crawlers, cookielib will allow you to get twice the result with half the effort! His most common partner modules are urllib and request under python.

Core Class

1. Cookie

This class implements the cookie standard defined by Netscape and RFC 2965 cookies, and can basically be understood as a certain piece of cookie data.

Part of the code is as follows. Do many attributes look familiar?

    self.domain_initial_dot = domain_initial_dot
    self.path = path
    self.path_specified = path_specified
    self.secure = secure
    self.expires = expires
    self.discard = discard
    self.comment = comment
    self.comment_url = comment_url
    self.rfc2109 = rfc2109

2.CookiePolicy

The main function of this class is to send and receive cookies, that is, to ensure that the correct cookie is sent to the corresponding domain name, and vice versa.

3.DefaultCookiePolicy

This class implements the CookiePolicy interface.

4.CookieJar

CookieJar is a collection of cookies, which can contain many Cookie classes and is our main operation object. There are a series of methods to support more detailed operations!

5.FileCookieJar

This class inherits from CookieJar. CookieJar only completes its life cycle in memory. The subclass of FileCookieJar can achieve data persistence and defines three interfaces: save, load, and revert.

6. MozillaCookieJar & LWPCookieJar

Two implementation classes, the inheritance relationship is as follows:

Python cookielib module for operating cookies

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn