What should I do if I want to use the urllib2 package in python3.6?

(*-*)浩
Release: 2019-07-09 10:30:07
Original
4330 people have browsed it

Python3.6.6 or python3.x cannot find the urllib2 syntax problem. After correcting it, an error will be reported that the urllib2 package is not installed.

What should I do if I want to use the urllib2 package in python3.6?

Through pip install urllib2 will also prompt that the package cannot be found. (Recommended learning:Python video tutorial)

Through pip3 install urllib2 will also prompt that the package cannot be found.

This is because builtwith depends on the urllib2 package. However, the urllib2 toolkit in Pyhton2 was split into two packages: urllib.request and urllib.error in Python3. As a result, the package cannot be found and there is no way to install it.

So you need to install the two packages urllib.request and install urllib.error, and then modify the import urllib2 in the builtwith package to import urllib.request and import urllib.error.

At the same time, the method functions in the code also need to be modified. Basically, urllib2.xxx is modified to urllib.request.xxx.

An example is provided below to help everyone understand:

#下载网页 import urllib.request import urllib.error def download(url): print('Downloading:',url) try: html=urllib.request.urlopen(url).read() except urllib.error as e: print('download error:',e.reason) html=None return html download('http://example.webscraping.com/')
Copy after login

For more Python-related technical articles, please visit thePython Tutorialcolumn to learn!

The above is the detailed content of What should I do if I want to use the urllib2 package in python3.6?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!