Sign Up

Sign In

Forget Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask question.

Import error: No module name urllib2

  • 0

Here’s my code:

import urllib2.request

response = urllib2.urlopen("http://www.google.com")
html = response.read()
print(html)

Any help?

Click to rate this post!
[Total: 0 Average: 0]
Share This Post
Share
  1. For a script working with Python 2 (tested versions 2.7.3 and 2.6.8) and Python 3 (3.2.3 and 3.3.2+) try:

    #! /usr/bin/env python
    
    try:
        # For Python 3.0 and later
        from urllib.request import urlopen
    except ImportError:
        # Fall back to Python 2's urllib2
        from urllib2 import urlopen
    
    html = urlopen("http://www.google.com/")
    print(html.read())
    • 0
Leave an answer

Leave an answer

Browse

close