python3的urllib的request模块
来源:互联网 发布:零基础学java第4版pdf 编辑:程序博客网 时间:2024/06/01 21:06
- urlopen
定义:
urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
*, cafile=None, capath=None, cadefault=False, context=None)
功能:像读文件一样读网页
#!/usr/bin/env python3# -*- coding:utf-8 -*-"打开网页"from urllib import requestbaidu = request.urlopen('http://www.baidu.com')baidu.readline()
2.urlretrieve
urlretrieve(url, filename=None, reporthook=None, data=None)
功能:下载网页到文件
#!/usr/bin/env python3# -*- coding:utf-8 -*-"打开网页"from urllib import requestbaidu = request.urlretrieve('http://www.baidu.com','/www/python/baidu.html')#如果urlretrieve不传文件名的话会自动生成,运行完程序可以删除request.urlcleanup()
3.urlcleanup
清除urlretrieve产生的临时文件,及opener对象
4.Request对象
class Request: def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None)# url是网址,data数据,header头消息,origin_req_host相当于referrer,method请求的方法(如get,post)
示例代码:
#!/usr/bin/env python3# -*- coding:utf-8 -*-from urllib.request import Requestrq = Request('http://www.baidu.com')这个类的主要干的事操作url,data,header@property 可以像访问属性一样访问方法@name.setter 可以向设置属性一样设置调用方法@name.deleter 删除属性
- request_host(request)
得到request对象的主机
0 0
- python3的urllib的request模块
- Python3: urllib.request 的使用
- python3 urllib.request抓资源的方式
- Python3中urllib.request.retrieve的使用
- python3 使用urllib.request模块,关于bytes和string的那些事
- python3 基于urllib模块的网络编程
- Python3学习笔记 urllib模块的使用
- Python中urllib.request模块的Request对象
- python3.x的urllib.request哪去了?
- Python3 的urllib实例
- urllib.request.Request的用法
- python3.4爬虫——urllib等模块的引用
- Python3学习笔记(urllib模块的使用)
- python3 urllib.request
- Python3:urllib.request详解
- Python3模块详解--老司机工具urllib模块详解之urllib.request子模块
- Python 3.6模块学习urllib的urllib.request.urlopen()函数学习
- Python3 urllib模块使用
- 4.9 CSS基础入门
- java静态变量
- DML语句
- AndroidStudio如何停止Git
- 数据库<4>
- python3的urllib的request模块
- MySQL --DML语句
- DML语句---插入单条数据记录
- 面向对象
- bzoj 1047 单调队列
- MySQL/ 字段
- 数据库
- Mac版本android studio快捷键
- 安装jar到本地maven仓库