How to download web page using python code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jalindar Gat
    New Member
    • Dec 2010
    • 2

    How to download web page using python code?

    Hi all, I am new bee in Python programming...
    I am trying to download web page using python code

    code:
    import urllib

    # Get a file-like object for the Python Web site's home page.

    f = urllib.urlopen( "http://www.python.org" )

    # Read from the object, storing the page's contents in 's'.

    s = f.read()

    f.close()

    and ERROR is
    Traceback (most recent call last):
    File "C:\Python26\cl k.py", line 5, in <module>
    f = urllib.urlopen( "http://www.python.org" )
    File "C:\Python26\li b\urllib.py", line 87, in urlopen
    return opener.open(url )
    File "C:\Python26\li b\urllib.py", line 203, in open
    return getattr(self, name)(url)
    File "C:\Python26\li b\urllib.py", line 338, in open_http
    h.endheaders()
    File "C:\Python26\li b\httplib.py", line 868, in endheaders
    self._send_outp ut()
    File "C:\Python26\li b\httplib.py", line 740, in _send_output
    self.send(msg)
    File "C:\Python26\li b\httplib.py", line 699, in send
    self.connect()
    File "C:\Python26\li b\httplib.py", line 683, in connect
    self.timeout)
    File "C:\Python26\li b\socket.py", line 498, in create_connecti on
    for res in getaddrinfo(hos t, port, 0, SOCK_STREAM):
    IOError: [Errno socket error] [Errno 11001] getaddrinfo failed

    Please let me know how it is comming....
    Thank you well in advance.....
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    It works fine for me. Perhaps there is a firewall or some other impediment that must be traversed.

    Comment

    Working...