httr::GET 在向同一网站发出请求时保留 cookie。
例子:
# Get login cookie
r1 <- GET("https://some.url/login", authenticate("foo", "bar"))
cookies(r1)
# returns a data frame of two cookies
# Make request that requires authentication cookie
# Only succeeds if r1 was made
r2 <- GET("https://some.url/data/?query&subset=1")
r2
Run Code Online (Sandbox Code Playgroud)
请注意,制作时r2您不必明确传递任何 cookie 信息,因为它们会自动存储在某处。
我想知道如何查询或删除这些存储的 cookie?
使用新句柄进行请求。
h1 <- handle('')
r1 <- GET("https://some.url/login", handle=h1, authenticate("foo", "bar"))
h2 <- handle('')
r2 <- GET("https://some.url/data/?query&subset=1", handle=h2)
Run Code Online (Sandbox Code Playgroud)