我正在检测带有 and 的单词,stringr
并regex
注意到我缺少几个项目,因为当有换行符时单词会被拆分。
引人注目的是,当我打印单元格的内容或在 RStudio 的数据查看器中查看它时,破坏单词的符号不可见。我只能看到在将数据框单元格的内容复制粘贴到控制台时,单词被拆分了。单词之间用一个小点隔开,例如 Schallenberg 表示为 Schallen[dot]berg(一个小点,垂直位于行的中间);
我认为分割单词的符号的不可见性与文本的起源有关。它们是通过 检索到的rvest
。然而,更引人注目的是,当我在网站上查看包含该符号的单词时,它们并没有被分割。
我的问题:如何删除这些原本不可见的符号?当已经从网站中提取文本时,stringr::str_squish.
我是否必须考虑它们?非常感谢!
library(rvest, quietly = T, warn.conflicts = F)
library(tidyverse, quietly = T, warn.conflicts = F)
web_link <- "https://www.parlament.gv.at//PAKT/VHG/XXVII/NRSITZ/NRSITZ_00006/fnameorig_797359.html"
df_txt <- web_link %>%
read_html(., encoding = "latin1") %>%
html_nodes("body > div.WordSection37 > p:nth-child(2) > b:nth-child(2) > span") %>%
html_text2() %>%
enframe(name = NULL,
value="text_raw") %>%
mutate(text_raw=text_raw %>% str_squish %>% str_trim(., "both"))
# There is a dot between Schallen - berg, but it's not visible
print(df_txt$text_raw)
#> [1] "Bundesminister für Europa, Integration und Äußeres Mag. Alexander Schallenberg, LL.M."
str_detect(df_txt$text_raw, "Schallenberg") #false
#> [1] FALSE
由reprex 包于 2021-04-08 创建(v1.0.0)