首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Python中,如何使urljoin按预期工作?

在Python中,如何使urljoin按预期工作?
EN

Stack Overflow用户
提问于 2015-07-28 16:40:23
回答 2查看 665关注 0票数 2

假设我有以下URL:

代码语言:javascript
运行
复制
url = https://www.example.com/thing1/thing2/thing3
next_thing = thing4

我想要以下网址:

代码语言:javascript
运行
复制
https://www.example.com/thing1/thing2/thing3/thing4

当我尝试

代码语言:javascript
运行
复制
>>> urlparse.urljoin(url,next_thing) 

我得到以下结果:

代码语言:javascript
运行
复制
https://www.example.com/thing1/thing2/thing4

为什么thing3被裁掉了?我该怎么解决呢?非常感谢!

EN

Stack Overflow用户

发布于 2015-07-28 16:44:05

不确定,但我想这可能是你要找的。

代码语言:javascript
运行
复制
url = 'https://www.example.com/thing1/thing2/thing3'
next_thing = 'thing4'
test = url + next_thing
print(test)

出炉:

代码语言:javascript
运行
复制
https://www.example.com/thing1/thing2/thing3/thing4
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31682359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档