0

我有这个网址:

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从 URL 中删除部分

4

1 回答 1

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
于 2014-08-18T22:52:45.157 回答