view page source or save after load
James Stroud
jstroud at mbi.ucla.edu
Thu Sep 21 06:17:33 EDT 2006
Gabriel Genellina wrote:
> At Thursday 21/9/2006 02:26, alex23 wrote:
>
>> page = urllib.urlopen('http://some.address')
>
> add .read() at the end
>
>> open('saved_page.txt','w').write(page).close()
>
> write() does not return the file object, so this won't work; you have to
> bind the file to a temporary variable to be able to close it.
Strictly speaking, "have to" is not perfectly correct. The ".close()"
part can simply be eliminated as the file should close via garbage
collection once leaving the local namespace.
James
More information about the Python-list
mailing list