使用 R 提取带有上标的 HTML table
Extract HTML table with superscripts using R
我正在尝试使用 R 在 this webpage 提取 table,代码如下:
library('htmltab')
url <- "http://www.math.leidenuniv.nl/~desmit/abc/index.php?set=2"
app.data<- htmltab(url, which = 3, rm_superscript = F, rm_whitespace=F, rm_invisible=F)
然而,上标随后被整合到正文中,所以table中的一个条目像3^{10}109输出为310109,这显然不是一回事。如果设置 rm_superscript = T
,则输出为例如3109,即完全没有上标,这也是不对的。我想要的是清楚地指示上标,所以输出像 3^{10}109。谁能帮忙?谢谢!
这是另一种方法。
library(xml2)
library(rvest)
URL <- "http://www.math.leidenuniv.nl/~desmit/abc/index.php?set=2"
pg <- read_html(URL)
提取 table 并将其转换回原始 HTML
tab <- as.character(html_nodes(pg, "table")[[3]])
手动将 <sup></sup>
替换为 {}
,将其转换回来并提取 table
dat <- html_table(read_html(gsub("</sup>", "}", gsub("<sup>", "{", tab) )))[[1]]
head(dat)
## quality size merit by on a b c
## 1 1 1.6299 6.81 8.64 ER 19870101 2 3{10}109 23{5}
## 2 2 1.6260 7.68 10.18 BdW 19850920 11{2} 3{2}5{6}7{3} 2{21}23
## 3 3 1.6235 15.70 26.86 JB JB 19940401 19·1307 7·29{2}31{8} 2{8}3{22}5{4}
## 4 4 1.5808 9.92 13.01 JB JB AN 19930312 283 5{11}13{2} 2{8}3{8}17{3}
## 5 5 1.5679 3.64 2.89 BdW 19880106 1 2·3{7} 5{4}7
## 6 6 1.5471 4.77 4.17 BdW 19880106 7{3} 3{10} 2{11}29
我正在尝试使用 R 在 this webpage 提取 table,代码如下:
library('htmltab')
url <- "http://www.math.leidenuniv.nl/~desmit/abc/index.php?set=2"
app.data<- htmltab(url, which = 3, rm_superscript = F, rm_whitespace=F, rm_invisible=F)
然而,上标随后被整合到正文中,所以table中的一个条目像3^{10}109输出为310109,这显然不是一回事。如果设置 rm_superscript = T
,则输出为例如3109,即完全没有上标,这也是不对的。我想要的是清楚地指示上标,所以输出像 3^{10}109。谁能帮忙?谢谢!
这是另一种方法。
library(xml2)
library(rvest)
URL <- "http://www.math.leidenuniv.nl/~desmit/abc/index.php?set=2"
pg <- read_html(URL)
提取 table 并将其转换回原始 HTML
tab <- as.character(html_nodes(pg, "table")[[3]])
手动将 <sup></sup>
替换为 {}
,将其转换回来并提取 table
dat <- html_table(read_html(gsub("</sup>", "}", gsub("<sup>", "{", tab) )))[[1]]
head(dat)
## quality size merit by on a b c
## 1 1 1.6299 6.81 8.64 ER 19870101 2 3{10}109 23{5}
## 2 2 1.6260 7.68 10.18 BdW 19850920 11{2} 3{2}5{6}7{3} 2{21}23
## 3 3 1.6235 15.70 26.86 JB JB 19940401 19·1307 7·29{2}31{8} 2{8}3{22}5{4}
## 4 4 1.5808 9.92 13.01 JB JB AN 19930312 283 5{11}13{2} 2{8}3{8}17{3}
## 5 5 1.5679 3.64 2.89 BdW 19880106 1 2·3{7} 5{4}7
## 6 6 1.5471 4.77 4.17 BdW 19880106 7{3} 3{10} 2{11}29