我是"新手"当涉及到R,但我真的想知道我如何从以下网站上刮下多张桌子(我不知道尺寸):
https://en.wikipedia.org/wiki/World_population
(具体来说,这里的代码是python中的代码:
from bs4 import BeautifulSoup
import urllib2
url1 = "https://en.wikipedia.org/wiki/World_population"
page = urllib2.urlopen(url1)
soup = BeautifulSoup(page)
table1 = soup.find("table", {'class' : 'wikitable sortable'})
trs = soup.find_all('tr')
tds = soup.find_all('td')
for row in trs:
for column in tds:
a = column.get_text().strip()
print a
break
答案 0 :(得分:1)
在R中,
u <- "https://en.wikipedia.org/wiki/World_population" # input
library(XML)
b <- basename(u)
download.file(u, b)
L <- readHTMLTable(b)
L
现在是u
中29个表的列表,每个表都是R数据框。