Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which should I be using: urlparse or urlsplit?

Which URL parsing function pair should I be using and why?

  • urlparse and urlunparse, or
  • urlsplit and urlunsplit?
like image 781
Matt Joiner Avatar asked Mar 29 '11 12:03

Matt Joiner


People also ask

What is the purpose of Urllib parse Urlparse?

parse — Parse URLs into components. This module defines a standard interface to break Uniform Resource Locator (URL) strings up in components (addressing scheme, network location, path etc.), to combine the components back into a URL string, and to convert a “relative URL” to an absolute URL given a “base URL.”

What does Urlparse return?

The return value from the urlparse() function is an object which acts like a tuple with 6 elements. The parts of the URL available through the tuple interface are the scheme, network location, path, parameters, query, and fragment.

What is Urlparse?

urlparse() This function parses a URL into six components, returning a 6-tuple. This corresponds to the general structure of a URL. Each tuple item is a string. The components are not broken up in smaller parts (for example, the network location is a single string), and % escapes are not expanded.

What is Urlparse module?

The urlparse module contains functions to process URLs, and to convert between URLs and platform-specific filenames.


1 Answers

Directly from the docs you linked yourself:

urllib.parse.urlsplit(urlstring, scheme='', allow_fragments=True)
This is similar to urlparse(), but does not split the params from the URL. This should generally be used instead of urlparse() if the more recent URL syntax allowing parameters to be applied to each segment of the path portion of the URL (see RFC 2396) is wanted.

like image 72
Sven Marnach Avatar answered Oct 03 '22 20:10

Sven Marnach