import requests
if __name__ == "__main__":
# 1. 指定url:
url = "http://sogou.com/"
# 2. 发起请求:
resp = requests.get(url=url)
resp.encoding = "utf-8"
# 3. 获取响应数据:.text返回的是字符串形式的响应数据
html = resp.text
# 4. 持久化存储数据:
with open("./sogou.html", "w", encoding="utf-8") as f:
f.write(html)
resp.close()
运行结果: