# 需求:爬取搜狗首页的页面数据import requestsif __name__ == ‘__main__‘: # 1指定url url = ‘https://www.sogou.com/‘ # 2发起请求 res = requests.get(url=url) # get方法会返回一个响应对象 # 3 获取响应数据.text返回的是字符串形式的响应数据 page_text = res.text print(page_text) # 4 持久化存储 fp = open(‘./sogou.html‘,‘w‘,encoding=‘utf-8‘) fp.write(page_text) print(‘爬取数据成功‘)
原文地址:https://www.cnblogs.com/huahuawang/p/12692218.html
时间: 2024-10-09 22:41:54