Python uses the requests library to simulate a simple example of logging in and fetching data

Source: Internet
Author: User
If you're still having headaches with Python's various urllib and urlibs,cookielib, or are still mad about Python's emulation of logging in and crawling data, take a look at our recommended Requests,python acquisition data emulation login Essentials!

This is also the recommended HTTP client library for Python:

This article is an example of a simulation login to illustrate, as for the collection of people please do it yourself.

The code is very simple, mainly to show the Python requests library is extremely simple, the code is as follows:

s = requests.session () data = {' user ': ' username ', ' passdw ': ' Password '} #post replaced with the address of the login, Res=s.post (' http://www.xxx.net/index.php? Action=login ', data); #换成抓取的地址s. Get (' http://www.xxx.net/archives/155/');

See! With just 4 lines of code, you can simulate logins.

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