我需要在txt文件中保存任何网站的HTML代码,这是一个非常简单的练习,但我对此有疑问,因为有一个函数可以做到这一点:
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()
Run Code Online (Sandbox Code Playgroud)
但这不起作用.