0

I have this URL:

www.domain.com/a/b/c/d,authorised=false.html

and I want to convert it into

www.domain.com/a/b/c/d.html

Please note I am using 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

returns www.domain.com/a/b/c/d,authorised=false.html but I don't know how to remove authorised=false part from the URL

2
  • Here you go: dpaste.com/3BY70EK Commented Aug 18, 2014 at 22:55
  • @Sushi For future reference, it is easier for people to respond if you include the code inline. Commented Aug 18, 2014 at 22:58

1 Answer 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.