Python requests库使用实例
来源:互联网 发布:mysql多表 union 用法 编辑:程序博客网 时间:2024/04/25 20:26
1、简单网络爬虫的通用框架
import requestsdef getHTML(url):try:r = requests.get(url)r.raise_for_status() #如果返回的状态不是200,引发HTTPError异常r.encoding = r.apparent_encodingreturn r.textexcept:return "产生异常"if __name__ == "__main__":url="http://www.baidu.com"print(getHTML(url))2、使用request下载网上的图片
import requestsimport osroot = "e://";url = "http://image.nationalgeographic.com.cn/2017/0316/20170316025141554.jpg";path = root + url.split("/")[-1]try:if not os.path.exists(root):os.mkdir(root);if not os.path.exists(path):r = requests.get(url)r.raise_for_statuswith open(path,'wb') as f:f.write(r.content)f.close()except:print("爬取失败")
-----中国大学MOOC嵩天老师的听课笔记
1 0
- Python requests库使用实例
- python的 requests库使用
- Python requests爬虫实例
- Python入门之requests库的安装与简单使用实例
- Python模拟登陆(使用requests库)
- Python Requests库简明使用教程
- Python库Requests的基础使用
- Python Requests库简明使用教程
- python requests 库使用小结(一)
- python requests 库使用小结(二)
- python-requests库的基本使用教程
- python中的requests使用
- Python-requests的使用
- Python Requests实例,查询成绩
- python爬虫入门--Requests库介绍及实例
- python requests库 笔记
- python requests库介绍
- Python之requests库
- Windows 7下Git SSH 创建Key的步骤
- fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
- HTML5基础加强css样式篇(css属性transform 函数(2D)的scale(),transform-origin,skew(),translate(),rotate() )(二十四)
- 数据库操作之事务
- NYOJ 82 迷宫寻宝(一)
- Python requests库使用实例
- Java高并发秒杀API之业务分析与DAO层
- 算法训练 寂寞的数
- NYOJ-91 阶乘之和(贪心)
- React学习之事件绑定处理机制(五)
- 动态规划-蓝桥杯-入学考试-采草药问题
- virtualenvs error: deactivate must be sourced. Run 'source deactivate' instead of 'deactivate'
- 安卓打包出现问题
- QT之GUI学习笔记(八)----菜单和工具条的优化