我正在尝试从以下URL抓取信息:
https://www.google.com/search?q=812-800%20H%20St%20NW
我想检索突出显示的“ 812 H St NW”:target
选择器小工具(chrome扩展名建议使用以下节点“ .desktop-title-content”]
但是,我得到的结果是NA,但我不知道如何解决此问题。
这是我的代码:
link <- "https://www.google.com/search?q=812-800%20H%20St%20NW"
xml2::read_html(link) %>%
rvest::html_node(".desktop-title-content") %>% rvest::html_text()
[1] NA
谢谢
我认为您希望在SelectorGadget不能很好地帮助您时检查源页面。在这种情况下,您只需要在<title>
和</title>
之间查找文本。我的文字中有一些多余的文字(即-Google搜索)。所以我最后将其删除。您可能没有。
read_html("https://www.google.com/search?q=812-800%20H%20St%20NW") %>%
html_nodes("title") %>%
html_text() %>%
sub(pattern = " -.*$", replacement = "")
#[1] "812-800 H St NW "