使用RSelenium下载PDF

xmq68pz9  于 2023-04-18  发布在  其他
关注(0)|答案(1)|浏览(147)

我尝试使用RSelenium的“County”级别选项--https://public.education.mn.gov/MDEAnalytics/DataTopic.jsp?TOPICID=11--从这个网站下载多个pdf。以下是我目前为止所做的,它可以用于下载pdf的第一个示例(也可以通过选择“County”作为级别,然后单击网站上的“List files”选项来获得此输出):

remDr <- remote_driver$client remDr$open() 
remDr$navigate("https://public.education.mn.gov/MDEAnalytics/DataTopic.jsp?TOPICID=11") # to navigate to a page
frames <- remDr$findElements('css', "iframe")
remDr$switchToFrame(frames[[1]])
remDr$findElement(using = "id",value = "cmbCOLUMN1")$clickElement()
option <- remDr$findElement(using = 'xpath', "//*/option[@value = 'County']")
option$clickElement()
remDr$findElement(using = "id",value = "button1")$clickElement()
report_frame <- remDr$findElement(using = "id",value = "report")
remDr$switchToFrame(report_frame)
remDr$findElement(using = "class", value = "buttonpdf")$clickElement()

如何使用RSelenium下载其余的pdf?我尝试使用$findElements方法,并尝试使用不同的“using”参数,但没有运气。我不太熟悉RSelenium和必要的html/css技能,这将有助于解决这个问题。

2uluyalo

2uluyalo1#

https://burtmonroe.github.io/TextAsDataCourse/Tutorials/TADA-RSelenium.nb.htmldropdown boxes in RSelenium和一个名为Russ的stackoverflow用户的帮助下,我想出了一个解决方案:

remDr <- remote_driver$client
remDr$open() # to launch
remDr$navigate("https://public.education.mn.gov/MDEAnalytics/DataTopic.jsp?TOPICID=11") # to navigate to a page
frames <- remDr$findElements('css', "iframe")
remDr$switchToFrame(frames[[1]])
remDr$findElement(using = "id",value = "cmbCOLUMN1")$clickElement()
option <- remDr$findElement(using = 'xpath', "//*/option[@value = 'County']")
option$clickElement()
remDr$findElement(using = "id",value = "button1")$clickElement()
report_frame <- remDr$findElement(using = "id",value = "report")
remDr$switchToFrame(report_frame)
Details_El <- remDr$findElements(using = "class", value = "buttonpdf")
# length(Details_El) to get the 339 length
for (i in 1:339) {
  Details_El[[i]]$clickElement()
}

相关问题