【问题标题】:Scrape html table with rvest. Why it only extracts a limited number of rows?用 rvest 抓取 html 表。为什么它只提取有限数量的行?
【发布时间】:2022-01-04 00:03:20
【问题描述】:

大家!

我可能需要一点帮助...

需要从表中提取所有行,但它只提取十 (10) 个结果...为什么?

这是我使用的代码:

library(rvest)

URL <- "https://cip.org.pt/associativismo/associados/"

CIP_html <- read_html(URL)
CIP_html

CIP_html %>% 
  html_nodes("table") %>% 
  html_table

还尝试了其他网页上的代码,它工作正常...提取所有行。

我无法弄清楚这个问题似乎是什么。

有人可以帮忙吗?如何从表中提取所有行?

谢谢!

【问题讨论】:

    标签: r rvest


    【解决方案1】:

    RSelenium 解决方案

    library(RSelenium)
    driver = rsDriver(browser = c("firefox"))
    remDr <- driver[["client"]]
    remDr$navigate(url)
    
    remDr$getPageSource()[[1]] %>% 
      read_html() %>%
      html_nodes(xpath= '//*[@id="table_1"]') %>% 
      html_table()
    # A tibble: 127 x 6
       Logo  Entidade                                                                                    Tipologia                   Setor Região  WEB              
       <lgl> <chr>                                                                                       <chr>                       <chr> <chr>   <chr>            
     1 NA    ""                                                                                          ""                          ""    ""      ""               
     2 NA    ""                                                                                          ""                          ""    ""      ""               
     3 NA    ""                                                                                          ""                          ""    ""      ""               
     4 NA    ""                                                                                          ""                          ""    ""      ""               
     5 NA    ""                                                                                          ""                          ""    ""      ""               
     6 NA    ""                                                                                          ""                          ""    ""      ""               
     7 NA    ""                                                                                          ""                          ""    ""      ""               
     8 NA    ""                                                                                          ""                          ""    ""      ""               
     9 NA    "ABIMOTA - Associação Nacional das Indústrias de Duas Rodas, Ferragens, Mobiliário e Afins" "Associação Multissetorial" ""    ""      "http://www.abim~
    10 NA    "ACIB - Associação Comercial e Industrial de Barcelos"                                      "Associação Regional"       ""    "Norte" "http://www.acib~
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-17
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-03-13
      • 2018-11-03
      • 2020-10-15
      • 2020-04-19
      相关资源
      最近更新 更多