knitr::opts_chunk$set(echo = TRUE)

In this example, I am interested in scraping the last tweets of a given webpage.

To do so, I will:

  1. Use playwright to emulate a web-browser
  2. Navigate to the twitter-page
  3. Automatically scroll down and collect all the presented tweets

Python environment

reticulate::use_condaenv("pw", required = TRUE)
options(python_init = TRUE)
library(reticulate)
library(playwrightr)
library(dplyr)
twitter_handle <- "elonmusk"

chrome <- new_browser("chrome", headless = F)
page <- chrome$pages[[1]]
page$goto(glue::glue("https://twitter.com"))
page$goto(glue::glue("https://twitter.com/{twitter_handle}"))
page$screenshot(path = "test.png")


benjaminguinaudeau/playwrightr documentation built on Nov. 8, 2023, 8:36 p.m.