-
Notifications
You must be signed in to change notification settings - Fork 13
/
get_tiers_urls.py
68 lines (46 loc) · 1.43 KB
/
get_tiers_urls.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
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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
=Get teams' urls=
Scrape TIERS_URLS to find all the urls of the teams that are within those tiers.
"""
import time
import bs4
import selenium_func as sel
from helper_functions import save_to_file
"""
Path to store the complete list of teams' urls
"""
TIERS_PATH = 'tiers_urls/tiers_urls.txt'
"""
Functions
"""
def get_tiers_urls():
"""
Searches each tier and extracts all the tiers' urls available.
"""
server, driver = sel.start_server_and_driver()
tiers_urls = []
try:
driver.get(sel.WHOSCORED_URL)
time.sleep(10) #Go to the browser, click All Leagues & Cups and then select All
content = driver.page_source
soup = bs4.BeautifulSoup(''.join(content), 'lxml')
regions = soup.find("div", {"id": "domestic-regions"})
li = regions.find_all("li")
for l in li:
ul = l.find("ul")
if ul is None:
continue
sub_li = ul.find_all("li")
for sub in sub_li:
href = sub.find('a', href=True)['href']
tiers_urls.append(href)
except Exception as e:
print("Error")
print(str(e))
save_to_file(tiers_urls, TIERS_PATH)
sel.stop_server_and_driver(server, driver)
return
if __name__ == '__main__':
get_tiers_urls()