Python3 using requests to login to everyone's movie website

Source: Internet
Author: User
Tags getstat
I have heard that requests's library is strong, but has not contacted, today contacted a bit, found before using URLLIB,URLLIB2 and other methods are really too rubbing ...

Here to write some simple use preliminary as a record

This article continues to practice the use of Requests login website, Renren has a feature is the sign-in function, need to log in every day to upgrade.

The following code Python code implements the process of using requests to log on to a Web site.

The following is a complete HTTP request header using the Fiddler capture package:

Python3 use requests to sign in to Renren website. PY Code:

"" "Python3 use requests to login to Renren website. py2016 May 11 07:33:59 codegay references requests Documentation: latest/Four common POST-submission data modes "" "Import reimport requests# Requests Install Command: Pip install requestsloginurl= ' ' surl= ' User/sign ' httphead={' Accept ': ' Application/json, Text/javascript, */*; q=0.01 ', ' Origin ': ' ', ' X-requested-with ': ' XMLHttpRequest ', ' user-agent ': ' mozilla/5.0 (Windows NT 6.3; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/50.0.2661.94 safari/537.36 ', ' content-type ': ' application/ X-www-form-urlencoded ',}data= "account= user name &password= password &remember=1" session=requests. Session () (loginurl,data=data,headers=httphead) print (login.cookies) #打印登录后取得到cookies对象print ( Login.json ()) Getstat=session.get (sURL). Text.split ("\ n") #访问签到页面, showing the last three login times [Print (R) for R in Getstat if "Three login Time" in R]

Compared with the two can be seen, there are some HTTP headers omitted to achieve the purpose, after all, after all the manual request of the head feel very troublesome.

In Fidder connection:keep-alive content-length: Two items can not be omitted, NCAT and other tools can not omit content-length, if you change the post data, The value of content-length needs to be corrected manually.

Content-length can be omitted in Python, I guess Python has handled it for us.

About Python3 use requests to login to everyone's film and television website to introduce so much to everyone, hope to help you!

  • Related Article

    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: 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.