1-1 爬取搜狗搜索首页的页面源代码

import requests


if __name__ == "__main__":
    # 1. 指定url:
    url = "http://sogou.com/"
    # 2. 发起请求:
    resp = requests.get(url=url)
    resp.encoding = "utf-8"
    # 3. 获取响应数据:.text返回的是字符串形式的响应数据
    html = resp.text
    # 4. 持久化存储数据:
    with open("./sogou.html", "w", encoding="utf-8") as f:
        f.write(html)
    resp.close()

运行结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ungoing/article/details/124083163
1-1