可以使用字符串的replace()方法来删除指定的字串。代码如下:

url = "http://zscx.osta.org.cn/"
new_url = url.replace(".cn", "")
print(new_url)

输出:

http://zscx.osta.org/

注意:这里使用了replace()方法,会将所有匹配的字串都替换掉。如果原始URL中还有其他的".cn",也会被删除。如果需要只删除最后一个".cn",可以使用rfind()方法找到最后一个出现的位置,然后再进行替换。


原文地址: http://www.cveoy.top/t/topic/bbsf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录