r tremeaud
r tremeaud

Reputation: 161

Scraping element from web using rvest

I'm trying to scrape element from the website : https://diga.bfarm.de/de/verzeichnis

my goal is to create a table from all the class="entity-app"

library (rvest)
document <- read_html("https://diga.bfarm.de/de/verzeichnis")
html_products <- document %>% html_elements("entity-app")

my goal is to become the following result

entity-app__header__name entity-app__info__list__header
First row
Second row

If someone had an idea or a line of thought, that would be very nice.

Thank you very much, dear future contributors. ;)

Upvotes: 0

Views: 282

Answers (1)

Carl
Carl

Reputation: 7540

This worked for me if it helps (using rvest's read_html_live and placing the results in a two-column data frame):

library(tibble)
library(rvest)

sess <- 
  read_html_live("https://diga.bfarm.de/de/verzeichnis") 

Sys.sleep(5)

tibble(
  header = sess |>
    html_elements(".entity-app__header__name") |>
    html_text2(),
  info = sess |>
    html_elements(".entity-app__subheader") |>
    html_text2()
)
#> # A tibble: 57 × 2
#>    header                                                             info      
#>    <chr>                                                              <chr>     
#>  1 actensio                                                           Vorläufig…
#>  2 Cara Care für Reizdarm                                             Dauerhaft…
#>  3 companion patella powered by medi - proved by Dt. Kniegesellschaft Dauerhaft…
#>  4 deprexis                                                           Dauerhaft…
#>  5 edupression.com®                                                   Dauerhaft…
#>  6 elevida                                                            Dauerhaft…
#>  7 elona therapy Depression                                           Vorläufig…
#>  8 Endo-App                                                           Dauerhaft…
#>  9 glucura Diabetestherapie                                           Vorläufig…
#> 10 HelloBetter Chronische Schmerzen                                   Dauerhaft…
#> # ℹ 47 more rows

Created on 2024-05-06 with reprex v2.1.0

Upvotes: 2

Related Questions