requests 模块爬取搜狗首页页面数据

 1 # 爬取搜狗首页的页面数据
 2 import requests
 3 # step_1 :指定url
 4 
 5 url = "https://www.sogou.com/"
 6 # step_2 :发起请求
 7 
 8 response = requests.get(url=url)
 9 # step_3 :获取响应数据
10 
11 page_text = response.text
12 print(page_text)
13 
14 # step_4 :持久化存储
15 
16 f = open("G:\daima\Python\\requests学习\\requests.txt", "w", encoding="utf-8")
17 f.write(page_text)
18 f.close()
19 print("爬取数据结束!!!!")

 

posted @ 2023-03-08 20:45  摆烂小T  阅读(61)  评论(0)    收藏  举报