【问题标题】:Web scraping in R with rvest and XML2 extract table使用 rvest 和 XML2 提取表在 R 中进行 Web 抓取
【发布时间】:2017-09-07 13:18:48
【问题描述】:

我希望从示例 URL 中提取包含排名和返回的表格 https://www.valueresearchonline.com/funds/fundSelector/returns.asp?cat=10&exc=susp%2Cclose&rettab=st

到目前为止尝试过 rvest

#Reading the HTML code from the website
webpage <- read_html(urlString)

#Using CSS selectors to scrap the section
tables <- webpage %>% html_node("tr") %>% html_text()
tables <- html_node(".fundtool_cat") %>% html_text()

我需要一个数据框/表格,其中包含方案名称以及提到的所有时期的排名和回报

【问题讨论】:

    标签: r rvest xml2


    【解决方案1】:
    library(rvest)
    urlString <- "https://www.valueresearchonline.com/funds/fundSelector/returns.asp?cat=10&exc=susp%2Cclose&rettab=st"
    urlString %>%
      read_html() %>%
      html_nodes(xpath='//*[@id="fundCatData"]/table[1]') %>%
      html_table(fill=T)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多