A web scraping example

This commit is contained in:
Jose 2022-10-27 12:27:40 -03:00
parent 68fbc33a3c
commit 8b24f381a0
2 changed files with 53 additions and 0 deletions

View File

@ -21,6 +21,10 @@ data using the R programming environment
* [[./script/iteration.R][Lapply, apply and for loop: brief introduction]]
** Web scraping
* [[./script/scraping2.R][Web scraping example]]
** Interesting packages
* [[./script/roadoi_package.R]['roadoi']]

49
script/scraping2.R Executable file
View File

@ -0,0 +1,49 @@
#' ---
#' title: ""
#' date: "2022-06-24"
#' author: "Jose"
#' output:
#' html_document:
#' code_folding: show
#' toc: yes
#' toc_float:
#' smooth_scroll: true
#' df_print: paged
#' highlight: zenburn
#' ---
#' remove objects
rm(list = ls())
#' Libraries
library(rvest)
library(crul)
url <- 'https://www.mdpi.com/search?q=pasture&journal=remotesensing'
url_parse = url
a = read_html(url)
html_children(a)[1] |> html_text()
str(a)
html_elements(a, "h1")
html_elements(a, "h2")
html_elements(a, "h3")
html_elements(a, "h4")
html_elements(a, "h2") |> html_text2()
html_elements(a, "p1")
html_elements(a, "p2")
html_elements(a, "p3")