字符串似乎是一个 space 字符,但实际上不是

String seeming to be one single space character, but isn't

我正在使用 rvest 进行一些网络抓取,我遇到了一些奇怪的事情。有一个字符串看起来像 " " 但实际上不是。我已经在两台计算机上复制了这个,一个 Mac OSX 系统 运行 R 3.6.3 和一个 Windows 10 系统 运行 R 3.6.3.

library(rvest)
library(stringr)
# scrape website, no issue
webpage <- rvest::read_html("https://www.usms.org/longdist/ldnats00/1hrf4044.php")
html <- rvest::html_nodes(webpage, css = "td")
results <- rvest::html_text(html)
# cleaning results a bit, no issue
results <- stringr::str_replace(results, "\\r\\n", "")
results <- results[results != ""]
# the mystery string
results[605]
[1] " "

如果我将 results[605]" " 进行比较,或者与打印 results[605]

的复制粘贴结果进行比较
results[605] == " "
[1] FALSE

如果我将 results[605] 存储在一个值

string_605 <- results[605]
string_605
[1] " "
results[605] == string_605
[1] TRUE
string_605 == " "
[1] FALSE

就像完整性检查一样

" " == " "
[1] TRUE

这个神秘字符串是什么,我该如何匹配它?我想像 results <- results[results != mystery string]

那样摆脱它

这里的字符串是<U+00A0>

我的解决方案总是尝试 clipr::write_clip(results[605]) 并粘贴到任何地方。然后你可以看到这个字符串的代码也可以粘贴到google中进行搜索:)

你可以这样做之后results <- results[results != '\U00A0']