i'm trying to get all content of a webpage using python and trying to put them all into a file.
Here is my code:
import urllib data = urllib.urlopen('http://www.site.net/index.html').read() #print data //if i ignore the rest part of this code the code is just working awesome...its printing the content of index.html f = open('somefile.html','w') //that i have already created. for lines in data.read(): print lines f.write(lines) #f.writelines('data') f.close()
I'm getting following errors:
Traceback (most recent call last): File "C:/Python24/showpage.py", line 5, in -toplevel- for lines in data.read(): AttributeError: 'str' object has no attribute 'read'
i'm using windows and Python 2.4.