Python3 uses requests to log on to Renren's video website, python3requests

Source: Internet
Author: User
Tags getstat

Python3 uses requests to log on to Renren's video website, python3requests

I have long heard that the requests library is powerful, but I haven't touched it yet. Today I have touched on it and found that urllib, urllib2, and other methods used in the past are too tricky ......

Here, we will write some simple operations and use them as a preliminary record.

This article continues to practice using requests to log on to the website. Renren TV has a sign-in function that requires daily sign-in to upgrade.

The python code below implements the process of logging on to a website using requests.

The following shows how to use fiddler to capture a complete HTTP Request Header:

POST http://www.zimuzu. TV /User/Login/ajaxLogin HTTP/1.1 Host: www. zimuzu. tvConnection: keep-aliveContent-Length: 102 Accept: application/json, text/javascript, */*; q = 0.01 Origin: http://www.zimuzu.tvX-Requested-With: XMLHttpRequestUser-Agent: mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36Content-Type: application/x-www-form-urlencodedDNT: 1 Referer: http://www.zimuzu. TV /user/loginAccept-Encoding: gzip, deflateAccept-Language: zh-CN, zh; q = 0.8, en; q = 0.6 Cookie: PHPSESSID = st40f3vohv6q16ec3atekimba0; last_item: expiration; last_item_date: 10733 = 1461856566; mykeywords = a % 3A2% 3A % 7Bi % 3A0% 3Bs % 3A6% 3A % 22% E7 % A1 % 85% E8 % B0 % B7 % 22% 3Bi % 3A1% 3Bs % 3A14% 3A % 22 Silicon + Valley % 22% 3B % 7D; zmz_rich = 2 account = your username & password = your password & remember = 1 & url_back = http % 3A % 2F % 2Fwww. zimuzu. TV % 2 Fuser % 2 Fsign

Python3 use requests to log on to Renren TV website. py code:

"Python3 use requests to log on to Renren's video website. py May 11, 2016 07:33:59 codegay references requests documentation: Restore POST submit data mode https://imququ.com/post/four-ways-to-post-data-in-http.html "import reimport requests # requests installation command: pip install requestsloginurl = 'HTTP: // www. zimuzu. TV/User/Login/ajaxLogin 'surl = 'HTTP: // www. zimuzu. TV/user/sign 'httphead = {'access': 'application/json, text/javascript, */*; q = 100', 'origin': 'http: // www. zimuzu. TV ', '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 = username & password = password & remember = 1" session = requests. session () login = session. post (loginurl, data = data, headers = httphead) print (login. cookies) # print the cookie object print (login. json () getstat = session. get (surl ). text. split ("\ n") # Visit the sign-in page, showing the last three logon Times [print (r) for r in getstat if "Three logon times" in r]

The comparison shows that some HTTP headers can be omitted to achieve the goal. After all, it is very troublesome to manually request the header each time.

In fidder, Connection: keep-alive Content-Length: two items cannot be omitted, and Content-Length cannot be omitted in ncat or other tools. If post data is changed, you need to manually modify the value of Content-Length.

Content-Length can be omitted in python. I guess python has helped us deal with it.

This article introduces python3's use of requests to log on to Renren's video website. I hope it will be helpful to 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: 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.