The simple reality of how Python keeps the login state

Source: Internet
Author: User

Batting practice is not a programmer just to share a train of thought, some time ago batting practice inadvertently try to use Python to keep the manual landing site

Status, when landing on a forum, is to use the cookie value to identify the user identity, as long as the cookie value is not invalid, you can

Long-term landing status.

The idea of using Python to stay in the log state:

    1. Manual Landing Forum

    2. Get cookie value with Firefox grab package plugin Httofox

    3. The value of the cookie transmitted by Python

The following is the Python implementation code

Import Urllib,urllib2

CJ = ' Acquired Cookie '

url = ' request page '

user = ' mozilla/5.0 (Windows; U Windows NT 6.1; ZH-CN; rv:1.9.2.13) gecko/20101203 firefox/3.6.13 '

Openr = Urllib2.build_opener (urllib2. Httpcookieprocessor ()) #创建打开器

Urllib2.install_opener (OPENR) #安装打开器

Self.openr.addheaders = [(' User-agent ', User),

(' Cookie ', CJ) #在请求头添加cookie

]

Self.con = Self.openr.open (Self.url). Read () #用打开器请求页面

Use this opener to request any page to remain logged in.


This article is from the "Old Buffalo Program" blog, make sure to keep this source http://itjishu.blog.51cto.com/2602918/1672795

The simple reality of how Python keeps the login state

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.