作用:
拆解 url 网址链接,协议、网络位置、路径等
必要操作:
py2:
>>> pip install urllib -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com >>> from urllib.parse import urlparse
py3:
>>> pip3 install urllib3 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com >>> from urllib3.parse import urlparse
帮助查看:
>>> help(urllib) >>> help(urllib3)
方法(函数):
>>> from urllib.parse import urlparse >>> urlparse('https://www.baidu.com/a/b/c?te8=20230207&sid=tosee_jd_850d6a84e1b028270nZ529S1FFdW&fromSource=2')
结果:
ParseResult(scheme='https', netloc='www.baidu.com', path='/a/b/c', params='', query='te8=20230207& sid=tosee_jd_850d6a84e1b028270nZ529S1FFdW&fromSource=2', fragment='')
取链接路径:
urlparse('https://www.baidu.com/a/b/c?te8=20230207&sid=tosee_jd_850d6a84e1b028270nZ529S1FFdW&fromSource=2').path
注意:
python3版本:[注] from urllib import parse 用parse.urljoin代替urlparse.urljoin
参考:
https://docs.python.org/zh-cn/3.10/library/urllib.parse.html
https://blog.csdn.net/qq_58487647/article/details/127702851
标签:parse,douban,Python,urllib,urlparse,url,https,com From: https://www.cnblogs.com/wutou/p/17097896.html