Home > Enterprise >  How to retrieve titles from google search using rvest
How to retrieve titles from google search using rvest

Time:07-31

I am working on a web scraping project using rvest. I have found useful posts about the task I am conducting but I am not getting the expected output. Basically, I want to get the names from titles after a search is done in google. For that I use next code (based on this post):

enter image description here

Is that possible, many thanks!

CodePudding user response:

Google searches change according to locale and also over time, so the list I get is different from yours. However, the xpath should be the same:

html_nodes(first_page, xpath = "//div/div/div/a/h3") %>% html_text()
#> [1] "Mario García Torres - Wikipedia"                              
#> [2] "Mario Torres (@mario_torres25) • Instagram photos and videos" 
#> [3] "Mario Torres - Regional manager Mexico and Central America"   
#> [4] "Mario Lopez Torres - A Furniture And Art Experience"          
#> [5] "Mario García Torres | The Guggenheim Museums and Foundation"  
#> [6] "Mario Torres - Player profile | Transfermarkt"                
#> [7] "Mario Torres Lopez - 33 For Sale on 1stDibs - 1stDibs"        
#> [8] "Mario Lopez Torres - 12 For Sale at 1stdibs"                  
#> [9] "Mario Lopez Torres Furniture | On the Town, Hispanic Heritage"
  • Related