我有这个网址:
www.domain.com/a/b/c/d,authorised=false.html
我希望将其转换为
www.domain.com/a/b/c/d.html
请注意我使用的是python 2.7。
from urlparse import urlparse
url = "www.domain.com/a/b/c/d,athorised=false.html_i_location=http%3A%2F%2Fwww.domain.com%2Fcms%2Fs%2F0%2Ff416e134-2484-11e4-ae78-00144feabdc0.html%3Fsiteedition%3Dintl&siteedition=intl&_i_referer=http%3A%2F%2Fwww.domain.com%2Fhome%2Fus"
o = urlparse(url)
url = o.hostname + o.path
print url
返回www.domain.com/a/b/c/d,authorised=false.html
,但我不知道如何从网址中删除authorised=false
部分
答案 0 :(得分:3)
import re
print re.sub(r',.+\.', '.', 'www.domain.com/a/b/c/d,authorised=false.html')
# www.domain.com/a/b/c/d.html