-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnationality.py
29 lines (23 loc) · 1.2 KB
/
nationality.py
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
from athlete import athleteResults
from webDriver import getSoup
def nationalityAthletes(browser, soup, url):
if len(url.split('&page_number=')) == 1 or len(url.split('?page_number=')) == 1: url = url + '&page_number='
else : url = url.replace('page_number=' + url.split('page_number=')[1], 'page_number=')
athletes = []
paginate_buttonsTag = soup.select('span a.paginate_button')
lenghtPages = int(paginate_buttonsTag[len(paginate_buttonsTag)-1].contents[0])
for indexPage in range(0, lenghtPages):
print('Nacionalidade: página ' + str(indexPage))
athletesLinks = soup.find('table', id='results_table').find_all('a')
for athleteLink in athletesLinks:
athleteLink = 'https://www.ibsf.org' + athleteLink['href'] # O link de retorno é apenas /en/component/events/event/(ID)
athleteSoup = getSoup(browser, athleteLink)
if not(athleteSoup) :
athletes.append(None)
continue
athlete = athleteResults(browser, athleteSoup)
athletes.append(athlete)
indexPage+=1
if indexPage == lenghtPages+1: break
soup = getSoup(browser, (url + str(indexPage)))
return athletes