Python urlparse总结
来源:互联网 发布:jquery.cookie.js用法 编辑:程序博客网 时间:2024/06/08 14:21
res = urlparse.urlparse(url,scheme,allow_fragments)
返回一个6-tuple,类型是ParseResult(scheme, netloc, path, params, query, fragment)
ParseResult类还有几个常用方法:
res.username
res.password
res.hostname
res.port
res.geturl()
urlparse.urlunparse(data)
返回一个string
data必须是six-item iterable
res = urlparse.urlsplit(url,scheme,allow_fragments)
返回一个5-tuple,类型是.SplitResult(scheme, netloc, path, query, fragment)
这里的path相当于urlparse的path+params,具体见例子
urlparse.urlunsplit(data)
返回一个string
data必须是five-item iterable
urlparse.urljoin(base, url, allow_fragments)
输出结果:
参照官方文档2.7.4:http://docs.python.org/2/library/urlparse.html
返回一个6-tuple,类型是ParseResult(scheme, netloc, path, params, query, fragment)
ParseResult类还有几个常用方法:
res.username
res.password
res.hostname
res.port
res.geturl()
urlparse.urlunparse(data)
返回一个string
data必须是six-item iterable
res = urlparse.urlsplit(url,scheme,allow_fragments)
返回一个5-tuple,类型是.SplitResult(scheme, netloc, path, query, fragment)
这里的path相当于urlparse的path+params,具体见例子
urlparse.urlunsplit(data)
返回一个string
data必须是five-item iterable
urlparse.urljoin(base, url, allow_fragments)
这个函数比较复杂,不同的数据得出的结果大不一样,而且容易出现错误,不建议用这个函数,详见下面几个例子
'''Created on 2013-4-15@author: xkey'''import urlparseurl = "https://www.google.com.hk:8080/home/search;12432?newwi.1.9.serpuc#1234"r = urlparse.urlparse(url)print rprint r.port,r.hostnameprint r.geturl()r = urlparse.urlsplit(url)print rparts = ["http","www.facebook.com","/home/email","132","parts","md5=?"]print urlparse.urlunparse(parts)print urlparse.urlunsplit(parts[0:5])base = "http://baidu.com/home"url = "index.html"print urlparse.urljoin(base, url)base = "http://baidu.com/home/action.jsp"url = "index.html"print urlparse.urljoin(base, url)base = "http://baidu.com/home/action.jsp"url = "/index.html"print urlparse.urljoin(base, url)base = "http://baidu.com/home/action.jsp"url = "../../index.html"print urlparse.urljoin(base, url)
输出结果:
ParseResult(scheme='https', netloc='www.google.com.hk:8080', path='/home/search', params='12432', query='newwi.1.9.serpuc', fragment='1234')8080 www.google.com.hkhttps://www.google.com.hk:8080/home/search;12432?newwi.1.9.serpuc#1234SplitResult(scheme='https', netloc='www.google.com.hk:8080', path='/home/search;12432', query='newwi.1.9.serpuc', fragment='1234')http://www.facebook.com/home/email;132?parts#md5=?http://www.facebook.com/home/email?132#partshttp://baidu.com/index.htmlhttp://baidu.com/home/index.htmlhttp://baidu.com/index.htmlhttp://baidu.com/../index.html
参照官方文档2.7.4:http://docs.python.org/2/library/urlparse.html
- Python urlparse总结
- python学习---urlparse模块
- python中的urlparse模块
- Python urlparse学习
- python urlparse详解
- Python——urlparse
- Python URLparse模块
- python的urlparse
- Python urlparse模块
- Python之urlparse模块
- python的urlparse
- python中使用urlparse
- Python学习——urlparse
- 关于python的urlparse.urljoin
- python 基于web脚本编程--urlparse
- Python——URL解析 urlparse学习
- Python urlparse模块解析URL下载
- python 分析http查询字符串 urlparse.parse_qs
- nachos学习资源
- 百度地图4之MyLocationOverlay的使用(Android)
- nginx文章部分列表
- C/C++中Sqlite使用简介
- 有关软件测试的精品文章(主要来自51Testing)
- Python urlparse总结
- wireshark安装
- 百度地图5之根据经纬度查询地址信息(Android) .
- 基础总结篇之二:Activity的四种launchMode
- U盘安装Linux,Windows多系统的方法
- OpenMP: 超线程Hyper-Threading和OpenMP
- 基于Maven的richfaces 4.x项目构建
- hash与map的区别联系应用
- awk sed grep 用法小结