【问题标题】:How to extract all cookies from Selenium (RSelenium) session and use them in GET request (httr)如何从 Selenium (RSelenium) 会话中提取所有 cookie 并在 GET 请求 (httr) 中使用它们
【发布时间】:2022-02-05 18:02:28
【问题描述】:

使用

cookies <- remDr$getAllCookies()

我能够从我的 RSelenium 会话中提取 cookie。

它们看起来像这样:

this answer可以看出,可以手动定义cookie名称和值。

但是,我不确定哪个特定 cookie 对我的需求至关重要,因此我想将所有这些 cookie 输入到我的 GET 请求中。

如何以编程方式完成?即将cookies "list of 33" 转换为 GET 请求的输入参数?

在理想的世界中,它看起来像这样:

cookies <- remDr$getAllCookies()
get_dm_location <- GET("https://api.xxxxxx.com/apis/ui/Products/117885",
                       set_cookies(cookies))

【问题讨论】:

    标签: cookies get httr rselenium


    【解决方案1】:

    假设 cookie 是一个命名列表然后简单地调用 unlist() 来生成所需的命名字符向量

    set_cookies(cookies %>% unlist())
    

    【讨论】:

      猜你喜欢
      • 2021-12-23
      • 1970-01-01
      • 2019-12-30
      • 2019-10-31
      • 1970-01-01
      • 2021-09-22
      • 2014-04-11
      • 2015-02-14
      • 2021-10-24
      相关资源
      最近更新 更多