os.system and wget

zunbeltz zunlatex at hotmail.com
Thu Nov 14 02:44:02 EST 2002


John Hunter <jdhunter at nitace.bsd.uchicago.edu> wrote in message news:<m2isz1e84k.fsf at mother.paradise.lost>...
> >>>>> "zunbeltz" == zunbeltz  <zunlatex at hotmail.com> writes:
> 
>     zunbeltz> os.system('wget -q -O foo.txt http://foo.html')
> 
> You may want to look at the popen commands:
> http://python.org/doc/current/lib/os-newstreams.html#os-newstreams.
> 
> For your example:
> 
>   import os
>   h = os.popen('wget -q -O foo1.txt http://foo.html')
>   h.close()
>   s = open('foo1.txt').read()
This didn't work. I'd an error mensage saying taht fool.txt didn't exist
But after finishing the script it was there.
> 
> Also, for the specific case of wget, python's builtin urllib can
> provide a bunch of these services
> 
>   import urllib
>   h = urllib.urlretrieve('http://foo.html', 'foo2.txt')
> 
> Or if you want to work with the returned data directly in python, you
> can use urlopen, which returns a filehandle
> 
>   h = urllib.urlopen('http://foo.html')
>   for line in h.readlines():
>      print line
> 
This has worked properly !! Thank you very much

> You can get fancier (cookies, recursive retrieval).  See websucker as
> an example python script built around urllib that has much of the wget
> functionality: http://www.pythonware.com/people/fredrik/websucker.htm.
> If you have the python src, you'll find it in the src tree at
> Tools/webchecker/websucker.py
> 
> John Hunter

Zunbeltz



More information about the Python-list mailing list