gruns / furl

🌐 URL parsing and manipulation made easy.
Other
2.6k stars 151 forks source link

How handle javascript:void(0) #150

Closed colinsarah closed 2 years ago

colinsarah commented 2 years ago

HI,here url is https://xxxxx.com/home/javascript:void(0); is there any func to get this:https://xxxxx.com/home

gruns commented 2 years ago

https://xxxxx.com/home/javascript:void(0); is a valid URL; i.e. none of the characters of javascript:void(0); are invalid path characters that need to be percent-encoded

as such, to get https://xxxxx.com/home from https://xxxxx.com/home/javascript:void(0); you can simply pop the last path segment. eg

>>> f = furl('https://xxxxx.com/home/javascript:void(0);')
>>> f.path.segments.pop()
>>> f.url
'https://xxxxx.com/home'

does that suffice for your use case?

colinsarah commented 2 years ago

thanks!