benjaminguinaudeau / playwrightr

An R-Wrapper für microsoft/playwright

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

playwightr

{playwrightr} provides access the python library playwright

Playwright emulates web browsers and enables reliable end-to-end testing for modern web apps.

Installation

  1. Install playwright (in this example, we install playwright in a new conda environment)
conda create -n pw python=3.7
conda activate pw
conda config --add channels conda-forge
conda config --add channels microsoft
conda install playwright
playwright install
  1. Install playwrightr from GitHub
# install.packages("devtools")
devtools::install_github("benjaminguinaudeau/playwrightr")

Loading playwrightr

This is a basic example which shows you how to solve a common problem:

reticulate::use_python("/home/ben/anac/bin/python", required = TRUE)
options(python_init = TRUE)
library(reticulate)
library(playwrightr)
library(dplyr)

pw_init(use_xvfb = F)

# Launch the browser
browser_df <- browser_launch(browser = "firefox", user_data_dir = tempdir(), headless = T)

# Create a new page
page_df <- new_page(browser_df)
page_df %>%
  goto("https://google.com")

page_df %>%
  get_by_selector("input") %>% 
  split(1:nrow(.)) %>%
  purrr::map_dfr(~{
    attrs <- get_all_attributes(.x)
    attrs
    
  }) %>%
  glimpse

Use Playwright to browse the web

chrome <- new_browser("chrome", headless = F)
page <- chrome$pages[[1]]

page$goto("https://google.com")

About

An R-Wrapper für microsoft/playwright


Languages

Language:R 100.0%