爬取搜狗主页的html 并且保存到本地
# 爬取搜狗主页面
import requests
# 表示不允许其他模块调用
if __name__ == "__main__":
# step1 指定url
url = 'https://lol.qq.com/main.shtml'
# step2 发起请求
# get方法会返回一个响应对象
response = requests.get(url=url)
# step3 获取响应数据 .text返回是字符串形式的响应数据
page_text = response.text
print(page_text)
# step4 持久化存储
with open('./lol.html', 'w', encoding="utf-8") as fp:
fp.write(page_text)
print('爬取数据结束')