I need save the HTML code of any website in a txt file, is a very easy exercise but I have doubts with this because a have a function that do this:
import urllib.request
def get_html(url):
f=open('htmlcode.txt','w')
page=urllib.request.urlopen(url)
pagetext=page.read() ## Save the html and later save in the file
f.write(pagetext)
f.close()
But this doesn't work.
wget
(on Unix/Linux, probably also on OSX, and also on Windows as part of CygWin) that can download a complete website. – EditionUnicodeEncodeError: 'charmap' codec can't encode character '\u2665' in position
:'( – Izettaizhevskpage = urllib.request.urlopen(url1) f = open("./offlinesaved.html", "wb") shutil.copyfileobj(page, f) f.close()
– Izettaizhevsk