我正试图从中搜集公共卫生的satistics数据 https://prog.nfz.gov.pl/APP-JGP/KatalogJGP.aspx
该页面显示两个相关的下拉列表。源仅显示顶部下拉列表的数据,下一个将仅在我在第一个下拉列表中选择后用数据(asp)动态填充。只有在我用两者做出选择之后,我才会看到我想要抓取的链接列表。
我的半自动解决方案:在两个下拉列表中选择,保存页面,然后离线删除链接列表。 我当前的代码显示我了解如何从组合框中获取数据并在选择后从页面获取数据:
#https://prog.nfz.gov.pl/app-jgp/
#From combo boxes I choose Year 2015 kat Ia and
#A group of procedures, eg. A1- xxxxxx
#Then I save the page locally to C:/myPage/
library(tidyverse)
library(rvest)
get_id <-
function (x, myString) {
require(stringr)
str_extract(x, paste0("(?i)(?<=", myString, "\\D)\\d+"))
}
# url <- "https://prog.nfz.gov.pl/APP-JGP/KatalogJGP.aspx"
url <- "C:/myPage/Narodowy Fundusz Zdrowia.htm"
pg <- read_html(url)
# The code below gets me the list from the first combo-box
# ContentPlaceHolder2_ddlSymylacjaJGP
n_values <-
html_nodes(pg, "#ContentPlaceHolder2_ddlSymylacjaJGP option") %>%
html_attr("value")
n_descr <-
html_nodes(pg, "#ContentPlaceHolder2_ddlSymylacjaJGP option") %>%
html_text()
selCatYear <- tibble(n_values,n_descr)
# The code below gets me the list from the second combo-box
#ContentPlaceHolder2_ddlKatalogJGP
n_values <-
html_nodes(pg, "#ContentPlaceHolder2_ddlKatalogJGP option") %>%
html_attr("value")
n_descr <-
html_nodes(pg, "#ContentPlaceHolder2_ddlKatalogJGP option") %>%
html_text()
setCatJGP <- tibble(n_values,n_descr)
# The code below gets me the list of urls I want.
# ContentPlaceHolder2_blKatalogJGP
n_values <-
html_nodes(pg, "#ContentPlaceHolder2_blKatalogJGP li a") %>%
html_attr("href")
n_descr <-
html_nodes(pg, "#ContentPlaceHolder2_blKatalogJGP li a") %>%
html_text()
setSingleJGP <- tibble(n_values,n_descr)
问题:如何在组合框中自动选择(依赖,动态创建内容)以便获取链接列表?是否可以只使用rvest和R?或其他工具(我听说过Selenium但从未使用它)。