rvest read_html returns 来自不同 url 的数据

rvest read_html returns data from a different url

我正在尝试收集一些关于几个 UFC 战士的数据。当我使用 rvest 读取 url 时,它总是 returns 不同的 url 数据。我得到的不是 Rob Font,而是随机的战士。 URL 可通过浏览器直接访问。这是网站的反抓取策略还是我遗漏了一些明显的东西?谢谢

#library(rvest)
#library(tidyverse)
url=read_html("https://www.tapology.com/fightcenter/fighters/rob-font")
name= url %>% html_nodes("div#stats.details.details_two_columns") %>% html_nodes('span') %>% html_text()

尽管使用你的代码我没有得到同样的错误?

library(rvest)
library(tidyverse)

ufc <- "https://www.tapology.com/fightcenter/fighters/rob-font" %>% 
  read_html() 

tibble(
  detail = ufc %>% html_elements("strong:nth-child(1)") %>% 
    html_text2() %>%  
    .[1:14] %>% 
    str_replace_all(":", ""), 
  value = ufc %>% 
    html_elements("#stats span:nth-child(2)") %>%  
    html_text2()
)

   # A tibble: 14 x 2
   detail                    value                   
   <chr>                     <chr>                   
 1 Given Name                "Robert Font"           
 2 Pro MMA Record            "19-5-0 (Win-Loss-Draw)"
 3 Nickname                  "N/A"                   
 4 Current Streak            "1 Loss"                
 5 Age                       "1987-06-25"            
 6 Last Fight                "December 04, 2021"     
 7 Weight Class              "Bantamweight"          
 8 Affiliation               "New England Cartel"    
 9 Height                    "5'8\" (173cm)"         
10 Career Disclosed Earnings "3,000 USD"          
11 Born                      "Tampa, Florida"        
12 Fighting out of           "Boston, Massachusetts" 
13 Head Coach                "Tyson Chartier"        
14 Other Coaches             "N/A"