在open.connection(x,“ rb”)中出现错误:使用RVest进行网络抓取时出现HTTP错误504。

时间:2019-08-06 12:09:14

标签: r rvest

我的代码突然停止并给出错误。

我正在尝试使用rvest抓取一些数据,但是抓取过程停止并显示错误。

我的代码:

library(rvest)
URL <- "http://stats.espncricinfo.com/ci/engine/records/team/series_results.html?class=2;id=1;type=team"
WS <- read_html(URL, quiet=TRUE)
URLs <- WS %>% html_nodes(".left:nth-child(1) .data-link") %>% html_attr("href") %>% as.character()
URLs <- paste0("http://stats.espncricinfo.com",URLs)
Catcher1 <- data.frame(P_URL=character())
for (i in URLs){
  WS1 <- read_html(i)
  P_URL <- WS1 %>% html_nodes(".content_link li:nth-child(1) .potMatchMenuLink") %>% html_attr("href") %>% as.character()
  temp <- data.frame(P_URL)
  Catcher1 <- rbind(Catcher1,temp)
}

Catcher2 <- data.frame()
for (i in Catcher1$P_URL){
  WS2 <- read_html(i)
  Venue <- WS2 %>% html_nodes(".cscore_info-overview") %>% html_text() %>% as.character()
  MarketValue <- WS2 %>% html_nodes("#gp-inning-01 .extras .cell+ .cell") %>% html_text() %>% as.character()
  if (length(MarketValue) > 0) {
    temp2 <- data.frame(Venue[1], MarketValue[1])
    Catcher2 <- rbind(Catcher2,temp2)} else {}
  cat("*")
}

我得到的错误:

  

open.connection(x,“ rb”)中的错误:HTTP错误504。

0 个答案:

没有答案
相关问题