I'm not sure why the SelectorGadget value is not working. Below is another (longer) route to get to the desired data.
library(rvest)
library(tidyverse)
my_region = "Southwest Pa."
link <- 'https://www.upmc.com/locations/hospitals'
pg <- read_html(url(link))
# scrape regions first
regions = html_nodes(pg, 'h2') %>% html_text()
# scrape regions and hospitals
node <- html_nodes(pg, "h2, .panel-title") %>% html_text()
# create data frame to filter to desired list
data.frame(node = node) %>%
mutate(region = ifelse(node %in% regions, node, NA)) %>%
fill(region) %>%
filter(region == my_region & region != node) %>%
pull(node)
#> [1] "UPMC Children's Hospital of Pittsburgh: Pittsburgh, Pa. (Lawrenceville)"
#> [2] "UPMC East: Monroeville, Pa."
#> [3] "UPMC Magee-Womens Hospital: Pittsburgh, Pa. (Oakland)"
#> [4] "UPMC McKeesport: McKeesport, Pa."
#> [5] "UPMC Mercy: Pittsburgh, Pa. (Uptown)"
#> [6] "UPMC Montefiore: Pittsburgh, Pa. (Oakland)"
#> [7] "UPMC Passavant – Cranberry: Cranberry Township, Pa."
#> [8] "UPMC Passavant – McCandless: Pittsburgh, Pa. (McCandless Township)"
#> [9] "UPMC Presbyterian: Pittsburgh, Pa. (Oakland)"
#> [10] "UPMC Shadyside: Pittsburgh, Pa. (Shadyside)"
#> [11] "UPMC St. Margaret: Pittsburgh, Pa. (Aspinwall)"
#> [12] "UPMC Western Psychiatric Hospital: Pittsburgh, Pa. (Oakland)"
Created on 2023-02-02 with reprex v2.0.2.9000