[英]Shiny App R - Scrubbing and Error
I'm building a Shiny App in R and I'm trying to scrub off the web information about the user's selected Pokemon, but I keep running into the problem of 'Error: SLL certificate problem' when trying to use read_html() 我正在R中构建一个Shiny App,并且试图清除有关用户选择的Pokemon的Web信息,但是在尝试使用read_html()时,我始终遇到“错误:SLL证书问题”的问题。
ui: ui:
sidebarPanel( ui <- fluidPage( selectInput(inputId = "pokemon1", 'Choose a Pokémon:', c(Pokemon$Name)))), mainPanel( verbatimTextOutput("value"))
And then the Server: 然后是服务器:
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) })
I'm using this data set: https://gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6 我正在使用此数据集: https : //gist.github.com/armgilles/194bcff35001e7eb53a2a8b441e8b2c6
and I have no idea where this error is coming from? 我不知道这个错误是从哪里来的?
Since you are trying to scrape from a website using a certificate (HTTPS), you will need to use the R package httr
. 由于您尝试使用证书(HTTPS)从网站抓取,因此您将需要使用R包httr
。 More explanation can be found here: How to webscrape secured pages in R (https links) (using readHTMLTable from XML package)? 在这里可以找到更多的解释: 如何使用R(https链接)(使用XML包中的readHTMLTable)对受保护的页面进行网络爬虫?
I used your code above (slightly edited) and came out with this minimal working example which works on my machine... 我在上面使用了您的代码(略作编辑),并给出了在我的计算机上工作的最小工作示例。
global.R 全球
library(shiny)
library(magrittr)
library(rvest)
Pokemon <- read.csv('pokemon.csv', stringsAsFactors = FALSE)
ui.R 用户界面
ui <- fluidPage(
sidebarPanel(
selectInput(inputId = "pokemon1", 'Choose a Pokemon:', c(Pokemon$Name))),
mainPanel(
verbatimTextOutput("value"))
)
server.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)
})
}
I get the following page 我得到以下页面
I hope this helps 我希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.