我正在用rvest
做一些网页抓取,我遇到了一些奇怪的事情。我在两台电脑上复制了这个字符串,一台运行R3.6.3的Mac系统和一台运行R3.6.3的Windows10系统。
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]
一样摆脱它
发布于 2020-04-17 00:26:55
这里的字符串是<U+00A0>
我的解决方案总是尝试clipr::write_clip(results[605])
并粘贴到任何位置。然后你可以看到这个字符串的代码也可以粘贴到google中进行搜索:)
在您可以这样做之后,results <- results[results != '\U00A0']
https://stackoverflow.com/questions/61254857
复制相似问题