-
问题描述
如题,url中经常会有各种参数,参数很容易写成dict形式,如果直接放到url中,代码会很长,不简洁。
有没有可以将dict转换成url的模块。
-
解决方案
还真有。
urllib.parse.urlencode()
-
urllib
urllib
is a package that collects several modules for working with URLs:urllib.request
for opening and reading URLsurllib.error
containing the exceptions raised byurllib.request
urllib.parse
for parsing URLsurllib.robotparser
for parsing robots.txt files (关于robots.txt参见《理解robots.txt on url||爬虫 》)
-
urllib.parse
The urllib.parse module defines functions that fall into two broad categories: URL parsing and URL quoting.
-
The URL Parsing functions focus on splitting a URL string into its components, or on comnbining URL components into a URL string.
-
The URL Quoting functions focus on taking program data and making it safe for use as URL components by quoting special characters and appropriately encoding non-ASCII text.
-
-
References
(20201202已解决)有没有dict字典转url的Python 库
最新推荐文章于 2024-05-27 17:00:50 发布