urltools (version 0.6)

extract_parameter: extract the value of an API parameter

Description

extract_parameter takes a vector of URLs and extracts the value associated with a specified parameter

Usage

extract_parameter(urls, parameter)

Arguments

urls
a vector of URLs.
parameter
the name of the parameter to search for. Case sensitive (so preprocessing with tolower may be useful).

Value

  • a character vector containing the value retrieved from each URL.

Details

People tend to put useful data in URL parameters, particularly around APIs. Extracting these is a pain unless you have a very consistent API, since you're essentially doing partial string-matching with a potentially arbitrary number of characters to include.

extract_parameter accepts a vector of URLs, and the name of the parameter (without an equals sign) and returns the value associated with that parameter. In the case that the parameter is represented multiple times within the URL, the first instance will be used.

See Also

replace_parameter for replacing, rather than extracting, values.

Examples

Run this code
extract_parameter(urls = "http://google.org/w/api.php?format=xml&smstate=all", parameter = "format")

Run the code above in your browser using DataLab