Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created March 1, 2020 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutannihilation/e2ea9a2084751cce23ca3102f13bf224 to your computer and use it in GitHub Desktop.
Save yutannihilation/e2ea9a2084751cce23ca3102f13bf224 to your computer and use it in GitHub Desktop.
library(chromote)

Sys.setenv(CHROMOTE_CHROME="/usr/bin/chromium")

b <- ChromoteSession$new()
b$Page$navigate("https://www.instagram.com/")
#> $frameId
#> [1] "7A4B060856C628A9F30A449F9F443F42"
#> 
#> $loaderId
#> [1] "40A73E0B9E658A449DFFC5531064C3E2"

p <- b$DOM$getDocument(wait_ = FALSE) %...>%
  { b$DOM$querySelector(.$root$nodeId, "article", wait_ = FALSE) } %...>%
  { b$DOM$getBoxModel(.$nodeId, wait_ = FALSE) }

b$wait_for(p)
#> Error in onRejected(...): code: -32000
#>   message: Could not find node with given id

screenshot_tmp <- tempfile(fileext = ".png")
b$screenshot(filename = screenshot_tmp)
#> [1] "/tmp/RtmpuUjhPz/file12fa6c6af649.png"
knitr::include_graphics(screenshot_tmp)

Created on 2020-03-01 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment