0
点赞
收藏
分享

微信扫一扫

【Python爬虫】1.爬搜狗主页

alanwhy 2022-01-04 阅读 26
# 步骤
# 指定url
# 发起请求
# 获取响应数据
# 持久化存储,存响应数据
# 爬取搜狗首页的页面数据
import requests
if __name__ == "__main__":
    #step1
    url = 'https://www.sogou.com/'
    #step2
    #get方法返回一个响应对象
    response = requests.get(url=url)
    #step3
    #text返回的是字符串形式的相应数据
    page_text = response.text
    print(page_text)
    #step4
    with open('./sogou.html' , 'w' , encoding='utf-8') as fp:#存到html文件里
        fp.write(page_text)
    print('爬取数据结束!!!')
举报

相关推荐

0 条评论