Python3. The difference between the X version and the 2.X version of the Urllib library

Source: Internet
Author: User
Tags urlencode python web crawler

Recently in learning to use Python3 to write a crawler, just started to write very dishes (last heard a big guy said that spent a day learning Python, the next day began to do a big reptile, the big guy is the big guy is I wait for the side can compare), Because I learned a little earlier 2 version so now learn to use the 3 version of the crawler will be a little different, the following main Urllib library of different.

What is a 1.urllib library?

The Urllib Library provides a series of functions for manipulating URLs. Python is a feature-specific powerful library, in Python2, respectively, there are urllib and urllib2 two libraries, and in Python3 Urllib and URLLIB2 merged into Urllib, do the crawler will often use this library!!!

2. When used 2. X is different from 3.X

In Python2. Use import urllib2 in X, corresponding to 3. Use import urllib.request in X

In Python2. Use import urllib in X, corresponding to 3. Use import urllib.request in X

In Python2. Use import urlparse in X, corresponding to 3. Use import Urllib.parse in X

In Python2. Use import Urllib.urlopen in X, corresponding to 3. Use import Urllib.request.urlopen () in X

In Python2. Use import Urllib.urlencode in X, corresponding to 3. Use import Urllib.request.parse.urlencode in X

In Python2. Use import urllib.quote in X, corresponding to 3. Use import Urllib.request.quote () in X

In Python2. Use import Urllib in X. Request, corresponding to 3. Use import urllib.request.Request in X

The above is what I know urllib some different, should still have, and so on learned to add it

By the way to the Learning crawler friend Amway A good book, is my reference to write the book

Reference:

<< proficient in Python web crawler >>-Wei Chi

Python3. The difference between the X version and the 2.X version of the Urllib library

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.