官方文档介绍https://docs.python.org/3/library/urllib.parse.html
但其实我们最常用的函数只有几个,
urljoin:
from urllib.parse import urljoin base = "http://www.baidu.com" last = "category/html" urljoin(base,last) >>>'http://www.baidu.com/category/html'
quote:
from urllib.parse import quote,unquote key = "要搜索的关键词" url_key = quote(key) url_key >>>'%E8%A6%81%E6%90%9C%E7%B4%A2%E7%9A%84%E5%85%B3%E9%94%AE%E8%AF%8D' unquote(url_key) >>>'要搜索的关键词'