PYTHON脚本练习

  1. 简单对象爬取练习


#爬取搜狗首页的页面数据
import requests
if __name__ == "__main__":
    #指定url


    url = "https://www.baidu.com/"
    #发起请求,成功之后会返回响应对象
    response = requests.get(url=url)
    #获取响应数据,text返回的是字符串形式的响应数据
    page_text = response.text
    print(page_text)
    #持久化存储
    with open('./sougou.html','w',encoding='utf-8') as fp:
        fp.write(page_text)
    print('爬取结束')

你可能感兴趣的:(python,前端,开发语言)