我正在尝试访问一个根据访问者类型设置 cookie 的网站:
library(httr)
url <- "https://www.blackrock.com/ca/individual/en/products/product-list#categoryId=1&lvl2=overview"
基本上我尝试过的所有东西都会返回这个......:
GET(url)
Response [https://www.blackrock.com/ca/individual/en/site-entry?targetUrl=%2Fca%2Findividual%2Fen%2Fproducts%2Fproduct-list%3FsiteEntryPassthrough%3Dtrue]
Status: 200
Content-type: text/html;charset=UTF-8
Size: 270 kB
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#" lang="en" xml:lang="en"><head><meta content="text/html;charset=UTF-8" http-equiv="Content-type...
<meta name="description" content="" />
<meta name="robots" content="noindex,noarchive,nocache" />
<meta property="og:title" content="Site Entry" />
<meta property="og:type" content="website" />
<meta property="og:image" content="/amer-retail-assets/include/common/images/blackrock_logo.png" />
<meta property="og:site_name" content="BlackRock" />
<meta property="og:locale" content="en_CA" />
<meta property="og:url" content="https://www.blackrock.com/ca/individual/en/site-entry?locale=en_CA" />
<link rel="canonical" href="https://www.blackrock.com/ca/individual/en/site-entry?locale=en_CA" />
因此,我尝试在 chrome 中手动传递网关或站点入口页面后复制 cookie:
cookie = c(`JSESSION_amer-retail01` = "AC91C17F269D8F6A136E576531FA6E05",
`UnicaID` = "10.39.18.249-1408392737241856",
`UnicaNIODID` = "NQHKNKQYKDm-YxUEYgX",
`_ga` = "GA1.2.127078965.1408392737",
`blkUserType-ca-one` = "institutional",
`s_pers` = "%20s_fid%3D14569E53C0F4EE51-3982590542B2DDA4%7C1471566685393%3B%20gpv%3Dca-one%257Cproducts%257Cproduct%2520list%7C1408410085400%3B%20s_nr%3D1408408285405-Repeat%7C1439944285405%3B%20s_pers_eVar15%3Dprospect%7C1411000285408%3B%20s_pers_prop19%3Danonymous%7C1411000285411%3B",
`s_sess` = "%20s_cc%3Dtrue%3B%20s_sq%3D%3B",
`s_vi` = "[CS]v1|29F92F108507B6C6-6000010A8000E2ED[CE]",
`ts-ca-one-locale` = "en_CA")
GET(url, set_cookies(.cookies = cookie), user_agent("Mozilla/5.0"))
这将返回相同的结果。
但是,当我查看示例时,httr
我认为设置 cookie 得到的结果不正确。
例如:
> example(set_cookies)
st_cks> set_cookies(a = 1, b = 2)
Config:
List of 1
$ cookie:"a1=;b2="
st_cks> set_cookies(.cookies = c(a = "1", b = "2"))
Config:
List of 1
$ cookie:"a1=;b2="
st_cks> GET("http://httpbin.org/cookies")
Response [http://httpbin.org/cookies]
Status: 200
Content-type: application/json
Size: 19 B
{
"cookies": {}
st_cks> GET("http://httpbin.org/cookies", set_cookies(a = 1, b = 2))
Response [http://httpbin.org/cookies]
Status: 200
Content-type: application/json
Size: 50 B
{
"cookies": {
"a1": "",
"b2": ""
}
我本来希望 httpbin.org 返回 a = 1 和 b = 1 而不是 a1 = 和 b2 =。难道我做错了什么?