1

我正在 R 中构建一个闪亮的应用程序,我试图清除有关用户选择的口袋妖怪的网络信息,但是在尝试使用 read_html() 时我一直遇到“错误:SLL 证书问题”的问题

用户界面:

  sidebarPanel(
        ui <- fluidPage(
            selectInput(inputId = "pokemon1", 'Choose a Pokémon:', c(Pokemon$Name)))),
   mainPanel(
             verbatimTextOutput("value"))
                                
                                

然后是服务器:

server <- function(input, output) {
  
  output$value <- renderPrint({
    pokemon <- input$pokemon1
    URLpokemon <- paste(c("https://bulbapedia.bulbagarden.net/wiki/", pokemon,"_(Pok%C3%A9mon)"), collapse="")
    # Read and parse HTML file
    pokemonSummary1 <- URLpokemon%>%
      read_html() %>% # R please help me read this HTML code
      html_nodes("p")%>% # type of HTML object
      .[[1]]%>%
      html_text()
    pokemonSummary2 <- URLpokemon%>%
      read_html() %>% # R please help me read this HTML code
      html_nodes("p")%>% # type of HTML object
      .[[2]]%>%
      html_text()
    pokemonSummary3 <- URLpokemon%>%
      read_html() %>% # R please help me read this HTML code
      html_nodes("p")%>% # type of HTML object
      .[[3]]%>%
      html_text()
    
    textAlmanac <- paste(c(pokemonSummary1,pokemonSummary2,pokemonSummary3), collapse=" ")
    
    paste(textAlmanac)
  })

我正在使用这个数据集:https ://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6

我不知道这个错误来自哪里?

4

2 回答 2

0

由于您尝试使用证书 (HTTPS) 从网站上抓取数据,因此您需要使用 R 包httr。更多解释可以在这里找到:如何在 R(https 链接)中网页抓取安全页面(使用 XML 包中的 readHTMLTable)?

于 2018-04-11T08:58:34.920 回答
0

我在上面使用了您的代码(稍作编辑)并提出了这个在我的机器上运行的最小工作示例......

全局.R

library(shiny)
library(magrittr)
library(rvest)

Pokemon <- read.csv('pokemon.csv', stringsAsFactors = FALSE)

用户界面

ui <- fluidPage(
    sidebarPanel(
        selectInput(inputId = "pokemon1", 'Choose a Pokemon:', c(Pokemon$Name))),
    mainPanel(
        verbatimTextOutput("value"))
)

服务器.R

server <- function(input, output) {

    output$value <- renderPrint({
        pokemon <- input$pokemon1
        URLpokemon <- paste(c("https://bulbapedia.bulbagarden.net/wiki/", pokemon,"_(Pok%C3%A9mon)"), collapse="")
        # Read and parse HTML file
        pokemonSummary1 <- URLpokemon%>%
            read_html() %>% # R please help me read this HTML code
            html_nodes("p")%>% # type of HTML object
            .[[1]]%>%
            html_text()
        pokemonSummary2 <- URLpokemon%>%
            read_html() %>% # R please help me read this HTML code
            html_nodes("p")%>% # type of HTML object
            .[[2]]%>%
            html_text()
        pokemonSummary3 <- URLpokemon%>%
            read_html() %>% # R please help me read this HTML code
            html_nodes("p")%>% # type of HTML object
            .[[3]]%>%
            html_text()

        textAlmanac <- paste(c(pokemonSummary1,pokemonSummary2,pokemonSummary3), collapse=" ")

        paste(textAlmanac)
    })
}

我得到以下页面

我希望这有帮助

于 2018-04-11T09:29:53.540 回答