Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.2 question

Tags:

python

urllib

I am using Python 3.2. I can import "urllib" library just like with 2.x version. But I can't find methods such as urlopen, urlretrieve, etc. What gives? How do I retrieve a webpage on v3.2?

I have tried to import urllib2 and urllib3 libraries. But my machine says it can't find those modules so not importable. Why these two newest libraries aren't supported in v3.2?

like image 722
Kalyan Avatar asked May 13 '11 06:05

Kalyan


3 Answers

You should use urllib.request. Example here.

like image 169
Timofey Stolbov Avatar answered Nov 19 '22 11:11

Timofey Stolbov


The 2.x docs mention that in Python 3.x, the modules have been split into urllib.request and urllib.error. If you have some Python 2.x code and want to convert the modules to 3.x, you may be able to use the 2to3 tool.

like image 25
icktoofay Avatar answered Nov 19 '22 09:11

icktoofay


It was changed in the newer versions and was split up to now be urllib.request.

from urllib.request import urlopen

A lot of what you're looking for is in the python library section on urllib.request and someone just mentioned an actual example from the documents that shows how the urllib.request.urlopen can be used.

like image 3
lcboris Avatar answered Nov 19 '22 09:11

lcboris