mmeutils.web package
Submodules
mmeutils.web.http module
mmeutils.web.m3u8 module
Module contents
Web Utilities
- mmeutils.web.get_file_name_from_url(url: str) str
Parses an URL and returns the last part which usually is a file name or directory/section.
- Parameters:
url (str) – The URL to parse.
- Returns:
The last part of the path ie. everything after the last slash excluding the query string.
- Return type:
str
- mmeutils.web.get_qs_dict(url: str) dict[str, list[str]]
Returns an URL query string as key-value dictionary.
Please note that query parameters can be specified multiple times thus the value for a specific key is a list of strings, not a single string.
- Parameters:
url (str) – The URL to parse for a query string.
- Returns:
A dictionary of query parameters.
- Return type:
dict[str, list[str]]
- mmeutils.web.get_qs_dict_flat(url: str) dict[str, str]
Returns an URL query string as key-value dictionary.
This utility function returns a flattened dictionary of query arguments, ie.: Query parameters can be specified multiple times - this function only yields the first argument of each parameter. Empty parameters are mapped to empty string.
- Parameters:
url (str) – The URL to parse for a query string.
- Returns:
A flattened dictionary of query parameters (first element of query argument or empty string).
- Return type:
dict[str, str]
- mmeutils.web.get_qs_value(url: str, key: str, default: Any | None = None) Any
Returns the value of a specific key of an URL query string.
- Parameters:
url (str) – The URL to parse for a query string.
key (str) – The key in the query string (&key1=value1&key2=value2 …) whose value to return.
default (Any) – The default value to return if the key was not found.
- Returns:
The value of key in the query string or default otherwise.
- Return type:
Any
- mmeutils.web.guess_user_agent(user_agents: dict, based_on_browser: str, default_ua: str) str
Returns the guessed browser’s user agent or a default one.
- Parameters:
user_agents (dict) – A dictionary of user agents for guessing.
based_on_browser (str) – Basis browser identifier. (TODO: clarify/rename)
default_ua (str) – The fallback user-agent string.
- Returns:
The guessed browser’s user agent or the default one.
- Return type:
str
- mmeutils.web.open_url(url_to_open: str) None
Opens an URL in a browser window.
- Parameters:
url_to_open (str) – The URL to open in the browser.
- mmeutils.web.split_url(url: str) NamedTuple
Splits an URL into absolute base and file name URLs without query strings or anchors.
Example URL:
Becomes:
- (
base_url=’https://my.server/some/path’, file_url=’https://my.server/some/path/interesting.txt’
)
- Parameters:
url (str) – The URL string to split.
- Returns:
A NamedTuple called SplitURL with keys (base_url, file_url).
- Return type:
NamedTuple