-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrapeFifaRankings.R
More file actions
68 lines (43 loc) · 1.27 KB
/
ScrapeFifaRankings.R
File metadata and controls
68 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
base_url = "https://www.transfermarkt.de/statistik/weltrangliste/statistik/stat/plus/0/galerie/0?datum=2010-05-26&page="
page = 1
scrapeRankings = function(page) {
columnValues = list()
new_url = paste0(base_url, page)
print(new_url)
new_url %>%
read_html() %>%
html_elements('.responsive-table') -> responsive
responsive %>%
html_elements('tr td:nth-of-type(1)') %>%
html_text() -> rank
print(rank)
responsive %>%
html_elements('tr td:nth-of-type(2)') %>%
html_text() -> nations
print(nations)
responsive %>%
html_elements('tr td:nth-of-type(4)') %>%
html_text() -> points
print(points)
columnValues = append(columnValues, list(rank))
columnValues = append(columnValues, list(nations))
columnValues = append(columnValues, list(points))
columnValues
}
df = NULL
for (i in 1:9) {
testData = scrapeRankings(i)
if(!is.data.frame(df)) {
df = data.frame(testData[[1]])
for (i in 2:length(testData)) {
df[i] = testData[[i]]
}
} else {
df_new = data.frame(testData[[1]])
for (i in 2:length(testData)) {
df_new[i] = testData[[i]]
}
df = bind_rows(df, df_new)
}
}
df