urltools (version 0.5)

url_param: extract the value of an API parameter

Description

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

Usage

url_param(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.

url_param 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.

Examples

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

Run the code above in your browser using DataLab