gpt4 book ai didi

Python urlparse,正确还是不正确?

转载 作者:太空狗 更新时间:2023-10-30 02:23:41 33 4
gpt4 key购买 nike

Python 的 urlparse 函数将 url 解析为六个部分(方案、netloc、路径和其他东西)

现在我发现解析“example.com/path/file.ext”不返回 netloc,而是返回路径“example.com/path/file.ext”。

不应该是netloc = "example.com"and path = "/path/file.ext"吗?

我们真的需要“://”来确定 netloc 是否存在吗?

Python 的票:http://bugs.python.org/issue8284

最佳答案

如果没有 scheme://,则无法保证 example.com 是一个域。您可以有一个名为 example.com 的目录。类似地,您可能有一个 url 'omfgroflmao/path/file.ext',您怎么知道 'omfgroflmao' 是本地网络上的一台机器(即 netloc)还是它是否意味着路径组件?

我看不出 Python 代码实际上是错误的,但也许文档需要明确说明在这种模棱两可的情况下的行为(我没有检查过)。

关于Python urlparse,正确还是不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563961/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com