I am using Windows, and I get the error:
ImportError: No module named urllib2
I think this is the solution for Linux. But how to set this in Windows?
I am using Python 3.2 and I am not able see urllib2
there in the LiB folder.
import urllib2 response = urllib2. urlopen('https://www.pythonforbeginners.com/') print response.info() html = response. read() # do something response. close() # best practice to close the file Note: you can also use an URL starting with "ftp:", "file:", etc.).
The Python "ModuleNotFoundError: No module named 'urllib2'" occurs because the urllib2 module has been split into urllib. request and urllib. response in Python 3. To solve the error, import the module as from urllib.
NOTE: urllib2 is no longer available in Python 3 You can get more idea about urllib.
The urllib module in Python 3 allows you access websites via your program. This opens up as many doors for your programs as the internet opens up for you. urllib in Python 3 is slightly different than urllib2 in Python 2, but they are mostly the same.
In python 3 urllib2 was merged into urllib. See also another Stack Overflow question and the urllib PEP 3108.
To make Python 2 code work in Python 3:
try: import urllib.request as urllib2 except ImportError: import urllib2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With