我正在尝试使用凭据登录网站,然后单击以下元素提交按钮。我在登录和导航到网址方面取得了部分成功。我不知道如何提交按钮单击并在新窗口中捕获文件打开。我正在使用rvest。
<input id="searchResultForm:printAllReports" type="submit" name="searchResultForm:printAllReports" value="View all reports" onclick="newWindow();" onmouseout="changeMouseOutRptButton(this.id)" onmouseover="changeMouseOverRptButton(this.id)" style="width:175px;padding-left:20px;padding-right:20px;" class="ERCommandLink1">
以下是我的尝试:
library(rvest)
library(httr)
url1<-"A link 1"
url2<-"A link 2"
session_initial <-html_session(url1) ## create session
form_login<-html_form(session_initial)[[1]] ## pull form from session
form_login_filled <- set_values(form_login,
"form1:id" = "user1",
"form1:pwd" = "pswd1")
session_login<-submit_form(session_initial,form_login_filled,submit="form1:loginButton")
session_desti<-session_login %>% jump_to(url2)
form_result<-html_form(session_desti)[[1]]
# Upto here things seems working - Getting status 200
# And can see the form elements of form_result
# Try - 1
session_test<-submit_form(session_desti,form_result, submit="searchResultForm:printAllReports")
# Try - 2
submit_form(session_desti,form_result, submit="searchResultForm:printAllReports",write_disk("check.pdf", overwrite = T))