3

hi i am trying to get the extension of the file called in a url (eg /wp-includes/js/jquery/jquery.js?ver=1.3.2 HTTP/1.1) and get the query parameters passed to the file too.

What would be the best way to the extension?

1 Answer 1

7

urlparse.urlparse() and os.path.splitext().

Sign up to request clarification or add additional context in comments.

4 Comments

You should probably just rsplit on . rather than use os.path in this case, as a URL and a filepath are different things. Using os.path.splitext would go wrong on an operating system where the file extension separator isn't .. Admittedly there are vanishingly few of those today.
wouldn't rsplit mathc the ver=1.3.2 path too ?
You would use it on the results of urlparse().
As a rule URL path manipulations should probably be done with posixpath.

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.