如何在Python 3中将网站的源代码复制到文本文件中?
编辑:为了澄清我的问题,这就是我所拥有的:
import urllib.request
def extractHTML(url):
f = open('temphtml.txt', 'w')
page = urllib.request.urlopen(url)
pagetext = page.read()
f.write(pagetext)
f.close()
extractHTML('http:www.google.com')
Run Code Online (Sandbox Code Playgroud)
我得到f.write()函数的以下错误:
builtins.TypeError: must be str, not bytes
Run Code Online (Sandbox Code Playgroud) python-3.x ×1