0
我正試圖在R中學習網絡抓取,並試圖從以下鏈接List of Cuisines on Wiki的各種表格中抓取數據。在頁面底部有幾張桌子,列出不同種類的美食,我想單獨閱讀。我嘗試使用CSS選擇器,但我認爲我使用他們錯了,這裏是我的代碼片段:使用R擷取網站中表格的數據
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表格填充的。
我真的很感激一些指導。謝謝。
我正在尋找類似的東西,它確實有幫助。 @hrbrmstr XPath當然似乎是一種更好的方法。 –