当前位置:   article > 正文

python中网络请求模块requests模块和urllib模块_requests进行网络请求导入什么模块

requests进行网络请求导入什么模块

requests模块作用:模拟浏览器发送请求。

使用:(requests模块的编码流程)

-导包 import requests

-指定url

-发起请求(get,post)

-获取响应的数据(页面)

-持久化存储(存储响应数据)

案例:爬取搜狗首页的页面数据:

#爬取搜狗首页
import requests
url = "http://www.sogou.com"
#step2:发起请求
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:
    fp.write(page_text)
print("爬取数据结束")

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/286608
推荐阅读
相关标签
  

闽ICP备14008679号