Use python to log on to and verify the website!

Source: Internet
Author: User
Use python to log on to and verify the website! Developer online builder.com.cn updated on: 2008-05-25Author: dreamingk Source: csdn keywords:
Website
Login
Python

However, if you encounter a small problem, you need to log on to the website by ID to open the page and download it. Later, xyb gave two login codes to implement the functions I needed. Later, I read the Lib ref document of python2.3 and found that httplib can be used for implementation. The Code is as follows:

# Loginbbs. py
Import urllib, httplib
Params = urllib. urlencode ({'username': 'pytest ',
# Here is the login parameter for post. You can modify it as your own parameter.
'Password': 'pypassword ',
'Cookies _ time': 1,
'Islogin': true })
Headers = {"Content-Type": "application/X-WWW-form-urlencoded", "accept": "text/plain "}

# Build Headers
Conn = httplib. httpconnection ("music.popv.net: 80 ")
# Create an HTTP connection. Remember not to add 'HTTP: // 'to the address and add a port.
Conn. Request ("post", http://music.popv.net/popv/login.asp, Params, headers)
# Sending login requests
Response = conn. getresponse ()
# Get a reply
Print response. Status, response. Reason
# Obtain the Request status
Data = response. Read ()
# Obtain the webpage content after login
Conn. Close ()
# Closing a connection

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.