【发布时间】:2018-03-09 00:32:48
【问题描述】:
我用来学习的编码:
import requests
r = requests.get("http://google.com")
f = open("./page.html", "w+")
f.write(r.text)
因此,如果我理解正确,这将创建一个 .html 文件并在其中写入我请求 (r) 的 google.com html 代码。
如果我现在运行:
import requests
params = {"q": "pizza"}
r = requests.get("http://google.com/search", params=params)
f = open("./page.html", "w+")
f.write(r.text)
f.write(r.text) 是否会重写 'r' 变量上的所有内容,就像它是一个空白文件一样,或者它只会用我添加到 'r' 中的新内容来编辑文件?不知道怎么问。谢谢
编辑:没关系我是菜鸟!如果我想追加使用f = open("./page.html", "a"),如果我想覆盖使用'w'
【问题讨论】:
-
你可以自己尝试一下:P
-
你为什么不通过执行它来尝试自己,它的附加或覆盖
标签: python html file python-requests