爬虫之requests模块介绍
2023-09-11 14:15:15 时间
爬虫之requests模块介绍
requests文档http://docs.python-requests.org/zh_CN/latest/index.html 【文档中包括的快速上手要精读,高级用法也要了解】
1.1 requests模块的作用:
- 发送http请求,获取响应数据 【1.导入2.调用get方法对目标url发送请求】
1.2 requests模块是一个第三方模块,需要在你的python(虚拟)环境中额外安装
pip/pip3 install requests
1.3 requests模块发送get请求
需求:通过requests向百度首页发送请求,获取该页面的源码
运行下面的代码,观察打印输出的结果
import requests
# 目标url
url = 'http://www.baidu.com'
# 向目标发送get请求
response = requests.get(url)
# 手动设置编码格式
response.encoding = 'utf8'
# 打印响应结果
print(response.text)
print(response.content)
print(response.content.decode())
运行效果:
相关文章
- Python 爬虫 性能 相关( asyncio 模块 --- 高性能爬虫 )
- Python爬虫之 正则表达式和re模块
- python爬虫知识点总结(九)Requests+正则表达式爬取猫眼电影
- 浅谈网络爬虫爬js动态加载网页
- Scrapy_redis框架原理分析并实现断点续爬以及分布式爬虫
- Scrapy框架中的crawlspider爬虫
- 爬虫之 lxml模块的安装与使用示例
- 爬虫之requests模块发送post请求
- 爬虫之requests模块中cookies参数的使用
- 《精通Python网络爬虫:核心技术、框架与项目实战》——1.2 为什么要学网络爬虫
- Go分布式爬虫笔记(十九) 4月Day3
- Python爬虫技术--基础篇--常用第三方模块chardet和psutil
- Python爬虫技术--基础篇--判断与循环语句
- Python 爬虫知识点
- Python网络爬虫反爬破解策略实战