我应该使用哪个:urlparse还是urlsplit?

2024-05-19 10:54:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我应该使用哪个URL parsing function pair,为什么?


Tags: urlfunctionparsingpair
2条回答

直接从the docs you linked yourself

urllib.parse.urlsplit(urlstring, scheme='', allow_fragments=True)
This is similar to urlparse(), but does not split the params from the URL. This should generally be used instead of urlparse() if the more recent URL syntax allowing parameters to be applied to each segment of the path portion of the URL (see RFC 2396) is wanted.

正如document所说
urlparse.urlparse返回6元组(附加参数元组)
urlparse.urlsplit返回5元组

Attribute   |Index | Value                                             | Value if not present
params    |     3   | Parameters for last path element | empty string


仅供参考:根据URL规范中的RFC2396参数

Extensive testing of current client applications demonstrated that the majority of deployed systems do not use the ";" character to indicate trailing parameter information, and that the presence of a semicolon in a path segment does not affect the relative parsing of that segment. Therefore, parameters have been removed as a separate component and may now appear in any path segment. Their influence has been removed from the algorithm for resolving a relative URI reference.

相关问题 更多 >

    热门问题