Title: | Fast Simple URL Parser |
---|---|
Description: | A fast and simple 'URL' parser package for 'R'. This package provides functions to parse 'URLs' into their components, such as scheme, user, password, host, port, path, query, and fragment. |
Authors: | Dyfan Jones [aut, cre] |
Maintainer: | Dyfan Jones <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.9999 |
Built: | 2025-01-13 13:30:07 UTC |
Source: | https://github.com/DyfanJones/urlparse |
This function encodes a character vector for use in URLs, escaping all special characters
except for those specified in the safe
parameter.
url_encoder(urls, safe = "") url_decoder(urls)
url_encoder(urls, safe = "") url_decoder(urls)
urls |
A character vector to be encoded/decoded. |
safe |
A character vector of extra characters that should not be encoded. |
A character vector with the encoded URLs.
library(urlparse) # Example 1: url_encoder("foo = bar + 5") # Example 2: # prevent special characters being encoded: url <- "https://example.com/path?query= 1+2" url_encoder(url, ":/?=") # Example 3: url_decoder(url_encoder("foo = bar + 5"))
library(urlparse) # Example 1: url_encoder("foo = bar + 5") # Example 2: # prevent special characters being encoded: url <- "https://example.com/path?query= 1+2" url_encoder(url, ":/?=") # Example 3: url_decoder(url_encoder("foo = bar + 5"))
Builds a URL string from its components.
url_build(url_components)
url_build(url_components)
url_components |
A list containing the components of the URL: scheme, host, port, path, query, and fragment.
|
A URL string constructed from the provided components
library(urlparse) url_build(list( scheme = "https", user = "", password = "", host = "host.com", port = 8000, path = "/path", query = "query", fragment = "fragment" ))
library(urlparse) url_build(list( scheme = "https", user = "", password = "", host = "host.com", port = 8000, path = "/path", query = "query", fragment = "fragment" ))
This function modifies a URL string by updating its components such as scheme, user, password, host, port, query, raw query, and fragment.
If any of these components are not provided (i.e., NULL
), the existing components of the URL are retained.
url_modify( url, scheme = NULL, user = NULL, password = NULL, host = NULL, port = NULL, path = NULL, query = NULL, fragment = NULL ) set_scheme(url, scheme) set_user(url, user) set_password(url, password) set_host(url, host) set_port(url, port) set_path(url, path) set_query(url, query) set_fragment(url, fragment)
url_modify( url, scheme = NULL, user = NULL, password = NULL, host = NULL, port = NULL, path = NULL, query = NULL, fragment = NULL ) set_scheme(url, scheme) set_user(url, user) set_password(url, password) set_host(url, host) set_port(url, port) set_path(url, path) set_query(url, query) set_fragment(url, fragment)
url |
A character string representing the original URL. |
scheme |
A character string for the new scheme (e.g., "http" or "https") or |
user |
A character string for the username or |
password |
A character string for the new password or |
host |
A character string for the new host or |
port |
A character string for the new port or |
path |
A character string for the new path or |
query |
A list or character of new query parameters or |
fragment |
A character string for the new fragment or |
A character string representing the modified URL.
library(urlparse) # Example 1: Modify the scheme and host of a URL url_modify( "https://user:[email protected]/path?query#fragment", scheme = "http", host = "example.com" ) # Example 2: Add a query parameter to a URL url_modify( "https://host.com/path", query = list(key1 = "value1", key2 = "value2") ) # Example 3: Change the fragment of a URL url_modify("https://host.com/path#old_fragment", fragment = "new_fragment")
library(urlparse) # Example 1: Modify the scheme and host of a URL url_modify( "https://user:[email protected]/path?query#fragment", scheme = "http", host = "example.com" ) # Example 2: Add a query parameter to a URL url_modify( "https://host.com/path", query = list(key1 = "value1", key2 = "value2") ) # Example 3: Change the fragment of a URL url_modify("https://host.com/path#old_fragment", fragment = "new_fragment")
Parses a URL string into its components.
url_parse(url)
url_parse(url)
url |
The URL string to parse. |
A list containing the components of the URL: scheme, user, password, host, path, raw_path, query, raw_query, and fragment.
library(urlparse) url_parse("https://host.com/path?query#fragment")
library(urlparse) url_parse("https://host.com/path?query#fragment")
Parses a vector of URLs into their respective components. It returns a data.frame where each row represents a URL, and each column represents a specific component of the URL such as the scheme, user, password, host, port, path, raw path, raw query, and fragment.
url_parse_v2(url)
url_parse_v2(url)
url |
A vector of strings, where each string is a URL to be parsed. |
A data frame with the following columns: - href: The original URL. - scheme: The scheme component of the URL (e.g., "http", "https"). - user: The user component of the URL. - password: The password component of the URL. - host: The host component of the URL. - port: The port component of the URL. - path: The decoded path component of the URL. - raw_path: The raw path component of the URL. - raw_query: The raw query component of the URL. - fragment: The fragment component of the URL.
library(urlparse) urls <- c("https://user:[email protected]:8080/path/to/resource?query=example#fragment", "http://www.test.com") url_parse_v2(urls)
library(urlparse) urls <- c("https://user:[email protected]:8080/path/to/resource?query=example#fragment", "http://www.test.com") url_parse_v2(urls)