Loading Required Libraries

library(RSelenium)
library(rvest)
library(stringr)

Path to Googe Chrome Driver

Set the system property for the chromedriver executable path

This is necessary for the Java-based Selenium server used by RSelenium.

Sys.setenv(CHROME_DRIVER_PATH = my_path)

Start the Selenium server and open the Chrome browser

open_browser <- rsDriver(browser = "chrome")
[1] "Connecting to remote server"

Get the remote driver (remDr) object

remote_driver <- open_browser[["client"]]

Defining search key word

meta_cognitive_strategies <- "((METACOGNITIVE-READING-STRATEGIES))"

Function to Extract Data from a page

extract_info <- function(page_source) {
  page <- read_html(page_source)
  titles <- page %>%
    html_nodes(".gs_rt") %>%
    html_text()
  authors <- page %>%
    html_nodes(".gs_a") %>%
    html_text()
  years <- str_extract(authors, "\\d{4}", "")
  authors <- str_replace(authors, "\\d{4}", "")
  urls <- page %>%
    html_nodes(".gs_rt a") %>%
    html_attr("herf")
  cited_by <- page %>%
    html_nodes(".gs_fl a:nth-child(3)") %>%
    html_text()
  cited_by <- as.integer(str_extract(cited_by, "\\d+"))
  data.frame(
    Article_Title = titles, Author_Names = authors, Publication_Year = years,
    Archive_Source = urls, Cited_By = cited_by
  )
}