使用RVest对Google搜索结果进行网页搜集时出现Character0错误

问题描述

我正在尝试抓取Google搜索标题。但是,不管我使用rvest做什么,结果总是返回character(0)

以下是搜索rstudio代码

library(rvest)
library(dplyr)

web1 <- read_html("https://www.google.at/search?q=rstudio") 
header <-web1 %>%
    html_nodes(".DKV0Md") %>%
    html_text()
header 

我在SelectorGadget中签入的节点名称,因此这不是问题。我该如何解决这个问题?

解决方法

也许我们可以使用:

library(rvest)
library(dplyr)
web1 %>% 
   html_nodes(xpath = '//div/div/div/a/div[not(div)]') %>% 
   html_text

输出:

#[1] "rstudio.com"        
#[2] "rstudio.cloud"           
#[3] "en.wikipedia.org › wiki › RStudio"    
# ....