【发布时间】:2016-01-17 14:15:00
【问题描述】:
我正在尝试在 R 中学习网络抓取,并且我正在尝试从以下链接 List of Cuisines on Wiki 中的各种表中抓取数据。在页面的底部有几个表格,列出了不同种类的美食,我想分别阅读它们。我尝试使用 css-selectors,但我认为我使用错了这是我的代码 sn-p:
require(rvest)
require(magrittr)
connection = html_session("https://en.wikipedia.org/wiki/List_of_cuisines")
connection %>% html_nodes("table:nth-child(1) a") %>% html_text()
#This lists down all the links in every table there is on that website
#I also tried connection %>% html_nodes("table:nth-child(2) a") %>% html_text()
#which gave a different list altogether
我试图生成的输出应该类似于
- 美食
- 所有美食列表
- 非洲美食
- 非洲美食一览
等等,这个列表是从 HTML 表格中填充的。
我非常感谢一些指导。谢谢。
【问题讨论】:
标签: css r web-scraping