load a web page and save source as text

Michael Hudson mwh21 at cam.ac.uk
Fri May 5 11:50:42 EDT 2000


"technology" <technology at mylinuxisp.com> writes:

> From python I want to be able to request a web age and save the source as
> text. do I import a html module?

No, urllib.

>>> text = urllib.urlopen("http://www.python.org").read()
>>> text[:100]
'<HTML>\012<!-- THIS PAGE IS AUTOMATICALLY GENERATED.  DO NOT EDIT. -->\012<!-- Tue May  2 14:10:44 2000 --'
 
> what is the syntax to send a html request and and then assign results to
> variable. I then would write the variable to a file correct?

Yup.

HTH,
Michael

-- 
58. Fools ignore complexity. Pragmatists suffer it. Some can avoid
    it. Geniuses remove it.
     -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html



More information about the Python-list mailing list