need help

juvy j juvy.jumalon at gmail.com
Thu Jan 29 04:52:01 CET 2009


Hi tkc,

Thanks so much.. it works! :-)
I used  the urllib.

and thanks also to everybody who replied.

jtj

On Thu, Jan 29, 2009 at 11:08 AM, Tim Chase
<python.list at tim.thechases.com>wrote:

>  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 = f.read()
>  >>> 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.
>
> -tkc
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090129/0f65f0a6/attachment.html>


More information about the Python-list mailing list