使用rstudio中的XPath访问某些类别的问题

发布于 2025-02-11 13:10:21 字数 440 浏览 1 评论 0原文

你好吗?我正在尝试访问一个特定的运动底网,我想获得正在播放的足球比赛的名称,但是当我尝试时,我只能访问所有活动名称,而我不知道为什么。我正在使用此代码:

library(rvest)
library(tidyverse)
library(xml2)

html="https://www.supermatch.com.uy/live_recargar_menu/"

a=rvest::read_html(html)

b2= a %>% html_node("body") %>% html_node(xpath="//li[@class='sport code_sport-1']") %>% 
    html_nodes(xpath="//span[@class='titulo']") %>% html_text() 

如您所见,此代码获取正在播放的所有事件的名称。

how are you? I am trying to access to a particular sportbetting web, i want to get the names of the football matches that are being played, but when i try i only get access to all the event names and i do not know why. I am using this code:

library(rvest)
library(tidyverse)
library(xml2)

html="https://www.supermatch.com.uy/live_recargar_menu/"

a=rvest::read_html(html)

b2= a %>% html_node("body") %>% html_node(xpath="//li[@class='sport code_sport-1']") %>% 
    html_nodes(xpath="//span[@class='titulo']") %>% html_text() 

As you can see, this code gets the name for all the events that are being played.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别再吹冷风 2025-02-18 13:10:21
library(tidyverse)
library(rvest)

page <- "https://www.supermatch.com.uy/live_recargar_menu/" %>%
  read_html()

tibble(
  title = page %>%
    html_elements(".titulo") %>%
    html_text(),
  score = page %>%
    html_elements(".marcador") %>%
    html_text(), 
  time = page %>%
    html_elements(".marcador+ span") %>%
    html_text() %>% 
    str_squish()
) 

# A tibble: 15 × 3
   title                                      score time         
   <chr>                                      <chr> <chr>        
 1 CS Emelec - Atletico Mineiro               0:1   1ª parte 18' 
 2 Nacional de Montevideo - Union de Santa Fe 1:0   1ª parte 18' 
 3 Brusque FC - Esporte Clube Bahia           0:1   PT 34'       
 4 Gremio FBPA - Londrina                     1:0   PT 34'       
 5 Fulgencio Yegros - Deportivo Santani       2:0   2ª parte 76' 
 6 Paraguay - Panama                          2:0   2ª parte 65' 
 7 Venezuela U20 - Bolivia U20                26:10 2do cuarto 6'
 8 Liu, L - Parikh, H                         1:1   3er set      
 9 Truwit, Teddy - Raab, J                    0:0   1er Set      
10 Ngounoue, M - Woog, M                      1:0   2do set      
11 Cheng, E - Lopez, Jackeline                1:0   2do set      
12 Moore, M - Pratt, S                        0:1   2do set      
13 Zhu, Jiayun - Horwood, S                   0:0   1er Set      
14 Nguyen, M - White, M                       0:0   1er Set      
15 Martincova, T - Pliskova, Karolina         0:0   No iniciado  
library(tidyverse)
library(rvest)

page <- "https://www.supermatch.com.uy/live_recargar_menu/" %>%
  read_html()

tibble(
  title = page %>%
    html_elements(".titulo") %>%
    html_text(),
  score = page %>%
    html_elements(".marcador") %>%
    html_text(), 
  time = page %>%
    html_elements(".marcador+ span") %>%
    html_text() %>% 
    str_squish()
) 

# A tibble: 15 × 3
   title                                      score time         
   <chr>                                      <chr> <chr>        
 1 CS Emelec - Atletico Mineiro               0:1   1ª parte 18' 
 2 Nacional de Montevideo - Union de Santa Fe 1:0   1ª parte 18' 
 3 Brusque FC - Esporte Clube Bahia           0:1   PT 34'       
 4 Gremio FBPA - Londrina                     1:0   PT 34'       
 5 Fulgencio Yegros - Deportivo Santani       2:0   2ª parte 76' 
 6 Paraguay - Panama                          2:0   2ª parte 65' 
 7 Venezuela U20 - Bolivia U20                26:10 2do cuarto 6'
 8 Liu, L - Parikh, H                         1:1   3er set      
 9 Truwit, Teddy - Raab, J                    0:0   1er Set      
10 Ngounoue, M - Woog, M                      1:0   2do set      
11 Cheng, E - Lopez, Jackeline                1:0   2do set      
12 Moore, M - Pratt, S                        0:1   2do set      
13 Zhu, Jiayun - Horwood, S                   0:0   1er Set      
14 Nguyen, M - White, M                       0:0   1er Set      
15 Martincova, T - Pliskova, Karolina         0:0   No iniciado  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文