0
所以我期望從TransferMarkt中獲取數據,特別是總理聯盟中玩家的名字和網址。我通過首先抓取聯盟中所有球隊的網址,然後通過這些球隊的個人球員來做這件事。我遇到的問題是數據沒有保存到框架中。當我試圖找到行數(no.of.rows)時,它仍然是零,所以我試圖打印框架(Catcher1),看看發生了什麼,它是空的!任何幫助將不勝感激,謝謝。網頁搜索:數據幀沒有填充
library(rvest)
URL <- "http://www.transfermarkt.com/premier-league/startseite/wettbewerb/GB1"
WS <- read_html(URL)
URLs <- WS %>% html_nodes(".hide-for-pad .vereinprofil_tooltip") %>% html_attr("href") %>% as.character()
URLs <- paste0("http://www.transfermarkt.com",URLs)
Catcher1 <- data.frame(Player=character(),P_URL=character())
for (i in URLs) {
WS1 <- read_html(i)
Player <- WS1 %>% html_nodes("#yw1 .tooltipstered")%>%html_text()%>%as.character()
P_URL <- WS1 %>% html_nodes("#yw1 .tooltipstered")%>%html_attr("href")%>%as.character()
temp <- data.frame(Player,P_URL)
Catcher1 <- rbind(Catcher1,temp)
cat("*")
}
print(Catcher1)
no.of.rows <- nrow(Catcher1)
odd_indexes<-seq(1,no.of.rows,2)
Catcher1 <- data.frame(Catcher1[odd_indexes,])
Catcher1$P_URL <- paste0("http://www.transfermarkt.com",Catcher1$P_URL)
絕對漂亮,謝謝! –
如果它有效,它可以幫助其他人勾選答案框,以便他們知道這是一個可行的答案 – hrbrmstr