get_cookies: Retrieve cookies from a jar

View source: R/get.r

get_cookiesR Documentation

Retrieve cookies from a jar

Description

Imagine you're reaching into a magical jar overflowing with those scrumptious digital delights from websites you've visited. The flavour? Up to you! Just select your desired output format.

Usage

get_cookies(
  domain,
  key = "",
  jar = default_jar(),
  as = c("data.frame", "string", "vector"),
  fixed = FALSE
)

Arguments

domain

A character string of the domain to retrieve cookies for. Accepts regular expression depending on the value of fixed.

key

An optional filter to retrieve only certain cookies by matching certain keys/names. Accepts regular expression depending on the value of fixed.

jar

A character string of the path to the cookie jar (the default is to use default_jar() to get a suitable directory).

as

A character string of the type of output to return.

fixed

If TRUE, domain and key are matched as is. If either domain or key, only those values are treated as is.

Details

The function returns cookies in one of three formats:

  • data.frame: is how cookies are stored internally and can be used for manual inspection.

  • string: is used by curl and httr2.

  • vector: is used by httr.

See vignette("cookies", "cookiemonster") for how to use cookies with these packages.

Value

Depending on the value of as, returns either a data frame, a character string, or a named vector.

Note

Your cookies are saved in an encrypted file. See encrypt_vec for more info.

See Also

add_cookies

Examples

# to conform with CRAN policies, examples use a temporary location. Do not use the options like this
options(cookie_dir = tempdir())

# put some cookies in the jar
add_cookies(cookiestring = "chococookie=delicious", domain = "example.com")
# Reach into your cookie jar and enjoy!
get_cookies("example.com")
# put different cookies into the jar (overwrites previous)
add_cookies(cookiestring = "oatmeal=delicious; peanutbutter=delicious", domain = "example.com")
add_cookies(cookiestring = "snickerdoodle=delicious", domain = "another.example.com")
# only get cookies for example.com, not another.example.com
get_cookies("^example.com")
# only get some cookies from example.com
get_cookies(domain = "^example.com", key = "peanut")

cookiemonster documentation built on May 29, 2024, 8:12 a.m.