通过启动器通过令牌进行POST请求

时间:2020-09-10 13:38:45

标签: r web-scraping v8 rvest splash-js-render

我要从robots.txt中允许的https://www.strava.com中抓取一些内容。 由于网站的许多部分都是使用javascript加密的,因此我想将splashrrvestV8一起使用。

Splashr很容易,因为render_html()基本上可以完成这项工作,但是我需要先登录。

登录站点https://www.strava.com/login每次刷新页面都会生成一个新令牌。所以我的问题是。在splashr中执行所需的POST请求的最简单方法是什么?

我已经知道如何访问令牌,但是在获取会话时我不知道如何在POST请求中将其组合。

page <- render_html(url ='https://www.strava.com/login', wait = 10) %>% 
write_html( file = 'test.html')
    read_page <- read_lines('test.html')
    token <- read_page %>%
str_extract(pattern = '.*authenticity_token.*') %>%
 .[is.na(.)==F]
 %>% .[2]
 %>%
      str_match(pattern = '.{88}\\"><div\\sclass=\\"facebook\\">') %>%
gsub(pattern = '\\"><div\\s.*', replacement = '')

0 个答案:

没有答案