目標:
刪除目標URL部分地址
代碼:
url = "https://home.cnblogs.com/GhostVip"
print("測試url地址:" + url)
def partially_deleted(url): # 網址刪除部分
templist = url.split("/")
print("split方法后的列表:" + str(templist))
templist.pop()
print("pop方法后的列表:" + str(templist))
url_partially_deleted = ("/").join(templist)
print("最后url地址:" + url_partially_deleted)
return url_partially_deleted
url_partially_deleted = partially_deleted(url)
測試結果:
測試url地址:https://home.cnblogs.com/GhostVip split后的列表:['https:', '', 'home.cnblogs.com', 'GhostVip'] pop方法后的列表:['https:', '', 'home.cnblogs.com'] 最后url地址:https://home.cnblogs.com
