library(rvest)

# create data frames for each section of data
data_A <- data.frame(
  protocol_url_segment = character(),
  A.1 = character(), A.2 = character(), A.3 = character(), A.3.1 = character(), A.3.2 = character(), A.4.1 = character(), A.5.1 = character(), A.5.2 = character(),  A.5.3 = character(), A.5.4 = character(), A.7 = character(), A.8 = character(),
  stringsAsFactors = FALSE
)

[TRUNCATED]
data_P <- data.frame(
  protocol_url_segment = character(),
  P.A = character(),  P.B = character(),
  stringsAsFactors = FALSE
)

# specify the base URL of the protocol page
protocol_url_segment <- "2015-003589-10/GR"
base_url <- "https://www.clinicaltrialsregister.eu/ctr-search/trial/"
url <- paste0(base_url, protocol_url_segment)

# read in the HTML content of the page
page <- read_html(url)

# extract the tricell rows as a list of nodes
tricell_rows <- page %>% html_nodes("tr.tricell")

# function to extract the text from row td elements and create a row vector 
extract_td_text <- function(row) {
  td_elements <- html_children(row)
  td_texts <- sapply(td_elements, html_text)
  td_texts <- trimws(td_texts)
  return(as.vector(td_texts))
}

# extract the text from the td elements in each row and store them in rows_list
rows_list <- lapply(tricell_rows, extract_td_text)

# create a data frame from the rows_list
tricell_df <- do.call(rbind.data.frame, c(rows_list, stringsAsFactors = FALSE))
colnames(tricell_df) <- c("Column1", "Column2", "Column3")


[TRUNCATED]


data_list <- list(data_A, data_B, data_D, data_E, data_F, data_G, data_H, data_N, data_P)
df_list <- list(df_A, df_B, df_D, df_E, df_F, df_G, df_H, df_N, df_P)





# Loop through each pair of data_ and df_ dataframes
for (k in 1:length(data_list)) {
  data_df <- data_list[[k]]
  merge_df <- df_list[[k]]
  
  if (nrow(merge_df) == 0) {
    next
  }
  
  new_row <- data_df[1,] # Create a new row based on the structure of the data_ dataframe
  
  # Set all values in the new row to NA except the protocol_url_segment column
  new_row[,-1] <- NA 
  new_row$protocol_url_segment <- protocol_url_segment 
  
  # Define the starting codes for new entries
  starting_codes <- c("B.1.1", "D.1.2andD.1.3", "G.4.1")
  
  entry_counter <- 1 # Initialize entry counter
  
  # Loop through each row in the df_ dataframe
  for (i in 1:nrow(merge_df)) {
    code <- merge_df[i, 1]
    value <- merge_df[i, 3]
    
    # Check if the code exists in the data_ dataframe
    if (code %in% colnames(data_df)) {
      # If the code is a starting code of a new entry and it is not the first row 
      # then add the current new_row to the data_ dataframe and create a new new_row
      if (code %in% starting_codes && i > 1) {
        # Assign the entry counter value to the corresponding column
        if (k == 2) { # data_B
          new_row$sponsor_number <- entry_counter
        } else if (k == 3) { # data_D
          new_row$IMP_number <- entry_counter
        } else if (k == 6) { # data_G
          new_row$network_number <- entry_counter
        }
        data_list[[k]] <- rbind(data_list[[k]], new_row)
        new_row <- data_df[1,]
        new_row[,-1] <- NA
        new_row$protocol_url_segment <- protocol_url_segment
        entry_counter <- entry_counter + 1 # Increment the entry counter
      }
      # Insert the value at the corresponding column in the new row
      new_row[, code] <- value
    }
  }
  
  # Assign the entry counter value to the corresponding column in the last new_row
  if (k == 2) { # data_B
    new_row$sponsor_number <- entry_counter
  } else if (k == 3) { # data_D
    new_row$IMP_number <- entry_counter
  } else if (k == 6) { # data_G
    new_row$network_number <- entry_counter
  }
  
  # Add the last new row to the data_ dataframe
  data_list[[k]] <- rbind(data_list[[k]], new_row)
}

# Update the data_ dataframes with the merged values
data_A <- data_list[[1]]
data_B <- data_list[[2]]
data_D <- data_list[[3]]
data_E <- data_list[[4]]
data_F <- data_list[[5]]
data_G <- data_list[[6]]
data_H <- data_list[[7]]
data_N <- data_list[[8]]
data_P <- data_list[[9]]
___________________________

This is working great!
Great! How can i loop through multiple protocol_url_segment values and compile them in the data_ dataframes?