## 导入requests
import requests
def spider1():
## 使用requests的get请求方法,请求搜狗引擎的首页
response = requests.get(url="https://www.sogou.com/")
## 打印输出首页的内容
print(response.text)
## 保存为sogou.html
with open("./sogou.html","w+",encoding="utf-8") as f:
## 写入搜狗首页的内容
f.write(response.text)
## 关闭文件
f.close()
if __name__ == '__main__':
## 使用spider1这个方法
spider1()
- 在3.requests文件夹里面创建souGou.py
- 爬取内容:爬取搜狗首页数据,并保存为html