I have a tibble which consists of scraped link text from the wayback machine. Some links were put into the wayback machine multiple times so we have duplicate links, but with slightly different endings.
Example:
https://www.bjjcompsystem.com/tournaments/1869/categories/2053148
https://www.bjjcompsystem.com/tournaments/1869/categories/2053148?locale=en
https://www.bjjcompsystem.com/tournaments/1869/categories/2053148?locale=pt-BR
The trouble is that since the URLs in the data frame have slight differences in the ending of their URLs as shown above, I'm not sure how I can get R to delete rows with duplicate URLs.
Is there a way to remove all the rows with duplicate links if those duplicates have slightly different endings?
This is what I've done, but this just splits out a vector with the formatted links. I wanted the formatted links in the original data frame.
library(rvest); library(tidyverse); library(stringr)
library(httr2); library(janitor)
link_text = "https://web.archive.org/web/timemap/json?url=https://www.bjjcompsystem.com/tournaments/1869/categories&matchType=prefix&collapse=urlkey&output=json&fl=original,mimetype,timestamp,endtimestamp,groupcount,uniqcount&filter=!statuscode:[45]..&limit=10000&_=1663136483842" %>%
request() %>%
req_perform() %>%
resp_body_json(simplifyVector = TRUE) %>%
as_tibble() %>%
row_to_names(1)
link_text = link_text[-c(1, 788:790),]
link_text2 = link_text
link_text2 = as.list(substr(link_text2$original, 1, 65))
link_text2 = link_text2[!duplicated(link_text2)]
head(link_text2)