{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/rvest/issues/72","labels_url":"https://api.github.com/repos/hadley/rvest/issues/72/labels{/name}","comments_url":"https://api.github.com/repos/hadley/rvest/issues/72/comments","events_url":"https://api.github.com/repos/hadley/rvest/issues/72/events","html_url":"https://github.com/hadley/rvest/issues/72","id":61875581,"number":72,"title":"Is there a way to set cookies before connecting to a webpage?","user":{"login":"MarcinKosinski","id":6773454,"avatar_url":"https://avatars.githubusercontent.com/u/6773454?v=3","gravatar_id":"","url":"https://api.github.com/users/MarcinKosinski","html_url":"https://github.com/MarcinKosinski","followers_url":"https://api.github.com/users/MarcinKosinski/followers","following_url":"https://api.github.com/users/MarcinKosinski/following{/other_user}","gists_url":"https://api.github.com/users/MarcinKosinski/gists{/gist_id}","starred_url":"https://api.github.com/users/MarcinKosinski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarcinKosinski/subscriptions","organizations_url":"https://api.github.com/users/MarcinKosinski/orgs","repos_url":"https://api.github.com/users/MarcinKosinski/repos","events_url":"https://api.github.com/users/MarcinKosinski/events{/privacy}","received_events_url":"https://api.github.com/users/MarcinKosinski/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-15T18:04:20Z","updated_at":"2015-04-15T19:09:47Z","closed_at":"2015-04-15T19:09:47Z","body":"One can use `cookies(html_session( webpage_url ) )` to check the session cookies\r\nbut is there a way to specify exact cookie before connecting to  a session? I'd like to download the\r\ncontent of a webpage but only when I enter with a cookie that starts with `4`.\r\n\r\nNow I am doing it in `while` loop that isn't the best solution:\r\n````{Ruby}\r\nlogic <- TRUE\r\nwhile( logic ){\r\nWP <- html_session(\"http://www.wp.pl/\")\r\nif ( substr( WP$response$cookies$statid, 1, 1) == \"4\" ){ logic <- FALSE}\r\n}\r\n````\r\n\r\nAny idea on how to do this?"},"comment":{"url":"https://api.github.com/repos/hadley/rvest/issues/comments/93535502","html_url":"https://github.com/hadley/rvest/issues/72#issuecomment-93535502","issue_url":"https://api.github.com/repos/hadley/rvest/issues/72","id":93535502,"user":{"login":"hadley","id":4196,"avatar_url":"https://avatars.githubusercontent.com/u/4196?v=3","gravatar_id":"","url":"https://api.github.com/users/hadley","html_url":"https://github.com/hadley","followers_url":"https://api.github.com/users/hadley/followers","following_url":"https://api.github.com/users/hadley/following{/other_user}","gists_url":"https://api.github.com/users/hadley/gists{/gist_id}","starred_url":"https://api.github.com/users/hadley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadley/subscriptions","organizations_url":"https://api.github.com/users/hadley/orgs","repos_url":"https://api.github.com/users/hadley/repos","events_url":"https://api.github.com/users/hadley/events{/privacy}","received_events_url":"https://api.github.com/users/hadley/received_events","type":"User","site_admin":false},"created_at":"2015-04-15T19:09:47Z","updated_at":"2015-04-15T19:09:47Z","body":"You'll need to parse the `set-cookie` header yourself. Start with:\r\n\r\n```R\r\nWP <- html_session(\"http://www.wp.pl/\")\r\nheaders <- httr::headers(WP)\r\n\r\ncookies <- unlist(headers[names(headers) == \"set-cookie\"])\r\ncrumbs <- stringr::str_split_fixed(cookies, \"; \", 4)\r\nstringr::str_split_fixed(crumbs[, 1], \"=\", 2)\r\n```"}}