need help

Tim Chase python.list at
Thu Jan 29 04:08:13 CET 2009

> Thanks for you reply. I am newbie in python.
> Im going to use HTTP.

If all you want is to download a file, you might want to look 
into using "wget" or "curl" (which work for both HTTP and FTP).  E.g.

   bash$ wget http://myothermachine/path/to/file.html

However, if you need to roll it into a script, Python's urllib 
module will do the trick

  >>> import urllib
  >>> url = "http://myothermachine/path/to/file.html"
  >>> f = urlib.urlopen(url)
  >>> out = file('python.txt', 'w')
  >>> for line in f: out.write(line)
  >>> out.close()
  >>> f.close()

If the content is small, you can just use

  >>> content =
  >>> out.write(content)

instead of the "for line in f: out.write(line)".  If you need to 
actually parse the HTML that's returned, the common suggestion is 
to use the BeautifulSoup add-on module which has worked for my needs.


More information about the Python-list mailing list