[英]Can rvest keep inline html tags such as <br> using html_table?
我試圖在R中寫一個表格,我已經用html格式給出了。 Rvest在將所有文本排除在表格之外非常有用,但我希望保持HTML表單中的內聯樣式。
例如,表中的文本可能是
"This is a sentence <BR> this is another sentence"
我想保留BR
我試過在整個表格中閱讀:
my_table <- my_table_html %>%
html_nodes("table") %>%
html_table(fill=TRUE)
我也嘗試在表格中選擇特定列:
my_column <- my_table_html %>%
html_nodes(".Tabletitle:nth-child(2)") %>%
html_text()
任何想法將不勝感激
library(rvest)
pg <- read_html("This is a sentence <BR> this is another sentence")
xml_find_all(pg, ".//br") %>% xml_add_sibling("p", "\n")
xml_find_all(pg, ".//br") %>% xml_remove()
html_text(pg)
## [1] "This is a sentence \n this is another sentence"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.