Reputation: 376
How can one set the domains for cookies in R using the rvest/httr/curl packages?
I know that one typically sets cookies using a named character vector of names and values (as ?set_cookies
reports). Is it possible to specify the domains as well? Or, maybe better yet, to send the whole seven-column Netscape spec that one gets back from httr::cookies()
?
The problem arises because I'm trying to automate the shibboleth-based login process for the UK Data Service, which uses a complex set of session cookies (see my earlier question). In the final step of the login process, the site passes two cookies with the same name (JSESSIONID
) but for different domains (#HttpOnly_wayf.ukfederation.org.uk
and shib.data-archive.ac.uk
). As just a named vector, though, the two JSESSIONID
s look alike. I've tried passing back just one or the other, but perhaps not surprisingly it seems that both are necessary.
Upvotes: 0
Views: 797
Reputation: 376
Adding the argument config = config(cookiejar = 'cookies.txt')
to your rvest
command, e.g., submit_form(session = s, form = f, config = config(cookiejar = 'cookies.txt'))
, does the trick. There's no need to have previously generated a file named cookies.txt, btw: it's all done automagically.
Upvotes: 1