【发布时间】:2020-07-16 00:12:55
【问题描述】:
如何在需要点击标签和按钮的地方抓取表格才能在网站上查看表格。
这些是在https://edudata.fldoe.org/ReportCards/Schools.html?school=0000&district=00查看表格的步骤:
- 点击“毕业及以后”
- 点击“高等教育继续率”
- 点击“创建中学后继续数据表”
- 点击“查看数据”
R 版本 3.6.2
我开始使用 rvest_0.3.5
read_html("https://edudata.fldoe.org/ReportCards/Schools.html?school=0000&district=00")
node <- url %>%
html_nodes("div.my_container.margin_top_170") %>%
html_nodes("div.col-sm-12.col-md-12.col-lg-12.mt-2") %>%
html_nodes("div") %>%
html_nodes("#accgrad")
node
[1] <div id="accgrad" class="collapse" aria-labelledby="gradhead" data-parent="#primaryaccordion"
我检查了 HTML 以及我想要的 id、类和父匹配,但我无法在我的 R 脚本中进一步定位表格。
我也尝试过使用 xml2_1.2.2
theurl <- getURL("https://edudata.fldoe.org/ReportCards/Schools.html?school=0000&district=00")
tables <- readHTMLTable(theurl)
tables
$`NULL`
A B C D F
1
$`NULL`
A B C D F
1
[[3]]
TS&I CS&I
1
我确实注意到其中有一个看起来像是在提取数据的脚本,但我没有足够的 html 知识来确定。
<script> $("#accgrad").load("accordions/acc_graduation.html");</script>
看起来该表位于:
<table id="tablePostsecenroll" class="display no-footer dataTable dtr-inline"
style="width:100%;" role="grid" aria-describedby="tablePostsecenroll_info">
一旦我可以访问该表,我就会想将它读入 data.frame。但是一旦我可以访问表格的 html 文本,我可能就可以弄清楚。
感谢您花时间解决这个问题!
【问题讨论】:
标签: html r xml web-scraping rvest