On Wednesday, October 15, 2014, ryguy7272 <<a href="mailto:ryanshuell@gmail.com">ryanshuell@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So sorry everyone. I've posted here several times today. This is VERY frustrating.<br>
<br>
So, I'm reading this link.<br>
<a href="https://docs.python.org/2/howto/urllib2.html" target="_blank">https://docs.python.org/2/howto/urllib2.html</a> <br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br></blockquote><div><br></div><div>Important note!: The "/2/" in the URL means those docs are for Python 2.x</div>When using Python 3, ensure that the docs you're consulting have a "/3/" in them instead.<br><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Fetching URLs<br>
The simplest way to use urllib2 is as follows:<br>
import urllib2<br>
response = urllib2.urlopen('<a href="http://python.org/" target="_blank">http://python.org/</a>')<br>
html = response.read()<br>
<br>
<br>
So, I fire up Python, and create a new file and name it and hit F5.<br>
<br>
All I have is thins in the file:<br>
import urllib2<br>
response = urllib2.urlopen('<a href="http://python.org/" target="_blank">http://python.org/</a>')<br>
html = response.read()<br>
<br>
It immediately produces this error:<br>
Traceback (most recent call last):<br>
File "C:/Python34/import_web_data.py", line 1, in <module><br>
import urllib2<br>
ImportError: No module named 'urllib2'<br>
<br></blockquote><div><br></div><div>You're using Python 3, and the urllib2 module no longer exists in Python 3. The URL/HTTP modules got refactored on Python 3. You want the `urllib.request` module instead.</div><div> </div>Although most folks nowadays use <a href="http://docs.python-requests.org/">http://docs.python-requests.org/</a> instead, though it's third-party and outside the std lib.