【发布时间】:2019-01-19 13:39:34
【问题描述】:
我想使用 rvest 从页面中抓取文本和超链接(.xlsx 和 .pdf 文件)。我不是很擅长这个,所以很难判断我是在处理一个复杂的网页,还是只是在犯新手错误。到目前为止我的代码:
my.url <- "https://comptroller.defense.gov/Budget-Materials/Budget2019/"
my.xpath <- '//*[@id="LiveHTMLWrapper92093"]/div/div'
x <- read_html(my.url) %>%
html_node(xpath = my.xpath)
{xml_node}
<div style="width: 710px; height: 600px; overflow: auto;">
[1] <h5 style="text-align: left; background-color: #dbdbe4;"><a name="press" style=" ...
[2] <p><a href="/Portals/45/Documents/defbudget/fy2019/fy2019_Press_Release.pdf" sty ...
[3] <p style="margin-top: 1px; margin-bottom: 0px;"><strong><span style="font-family ...
[4] <p style="margin-top: 1px; margin-bottom: 0px;"><strong><span style="font-family ...
[5] <p><strong>\n- <a href="https://www.defense.gov/News/Transcripts/Transcript-View ...
[6] <h5 style="text-align: left; background-color: #dbdbe4;"><a name="summary" style ...
[7] <div style="height: 50px;">\n<a href="/Portals/45/Documents/defbudget/fy2019/FY2 ...
[8] <strong><strong>\n<b><strong>\n<b>\n<strong>\n</strong>\n<strong>\n</strong>\n<s ...
理想情况下,我想输出一个数据框,其中包含一列中的文本和另一列中的关联 href。
【问题讨论】: