我要从robots.txt中允许的https://www.strava.com中抓取一些内容。
由于网站的许多部分都是使用javascript加密的,因此我想将splashr
或rvest
与V8
一起使用。
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 = '')