【发布时间】:2017-11-29 01:59:01
【问题描述】:
试图从维基百科的人类发展指数中抓取前 8 个表(非常高、高、中、低)。
开始但得到一个零列表。我究竟做错了什么? R 新手 :(
libray(rvest)
url <- "https://en.wikipedia.org/wiki/List_of_countries_by_Human_Development_Index#Complete_list_of_countries"
webpage <- read_html(url)
hdi_tables <- html_nodes(webpage, 'table')
head(hdi_tables, n = 10)
scrape <- url %>%
read_html() %>%
html_nodes(xpath = '//*[@id="mw-content-text"]/div/div[5]/table/tbody/tr/td[1]/table') %>%
html_table()
head(scrape, n=10)
【问题讨论】:
-
可能更容易得到原始数据from the source。您可以选择
HDI并下载 CSV 文件,直到 2015 年。维基百科上的表格是 2016 年的估计值。
标签: html r screen-scraping rvest