【发布时间】:2018-10-13 06:05:52
【问题描述】:
我正在尝试从此网页上的“团队统计”表中获取数据:
https://www.hockey-reference.com/teams/CGY/2010.html
我在网络抓取方面没有太多经验,但已经尝试过使用 XML 包,现在使用 rvest 包:
library(rvest)
url <- html("https://www.hockey-reference.com/teams/CGY/2010.html")
url %>%
html_node(xpath = "//*[@id='team_stats']")
最终得到一个看起来像单个节点的东西:
{xml_node}
<table class="sortable stats_table" id="team_stats" data-cols-to-freeze="1">
[1] <caption>Team Statistics Table</caption>
[2] <colgroup>\n<col>\n<col>\n<col>\n<col>\n<col>\n<col>\n<col>\ ...
[3] <thead><tr>\n<th aria-label="Team" data-stat="team_name" sco ...
[4] <tbody>\n<tr>\n<th scope="row" class="left " data-stat="team ...
我如何解析这个以获得两行表中的标题和信息?
【问题讨论】:
标签: r xml web-scraping rvest