Skip to content

Commit 43c0839

Browse files
Shrikant JituriShrikant Jituri
authored andcommitted
epl team scrap
1 parent e522905 commit 43c0839

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

epl_team.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import requests
2+
from lxml import html
3+
from collections import defaultdict
4+
5+
6+
# Pre Stuff
7+
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'}
8+
teams = ['Manchester City', 'Manchester United', 'Tottenham Hotspur', 'Chelsea', 'Arsenal', 'Watford', 'Newcastle United', 'Burnley', 'Liverpool', 'Southampton', 'Huddersfield Town', 'Brighton and Hove Albion', 'West Bromwich Albion', 'Leicester City', 'Swansea City', 'West Ham United', 'Stoke City', 'Everton', 'Bournemouth', 'Crystal Palace']
9+
teams.sort()
10+
url = 'https://www.premierleague.com/tables'
11+
concat_url = 'https://www.premierleague.com/'
12+
13+
14+
# Get parsed page using lxml
15+
def get_parsed_page(url):
16+
response = requests.get(url, headers=headers, timeout=10)
17+
parsed_page = html.fromstring(response.content)
18+
return parsed_page
19+
20+
21+
# Main
22+
print(teams)
23+
team = raw_input('Enter Team Name from above list: ')
24+
parsed_page = get_parsed_page(url)
25+
26+
# Getting required details
27+
a_teams = parsed_page.xpath('//tbody[@class="tableBodyContainer"]//td[@class="team"]/a/span[@class="long"]/text()')
28+
points = parsed_page.xpath('//tbody[@class="tableBodyContainer"]//td[@class="points"]/text()')
29+
next_match_link = parsed_page.xpath('//tbody[@class="tableBodyContainer"]//td[@class="nextMatchCol hideMed"]//a/@href')
30+
31+
ref = defaultdict(list)
32+
33+
for i, (a,b,c) in enumerate(zip(a_teams, points, next_match_link)):
34+
ref[a] = [i+1, a, b, concat_url + c]
35+
36+
print("Current Position: "+str(ref[team][0]))
37+
print("Total Points: "+str(ref[team][2]))
38+
print("Next Match: "+ref[team][3])

0 commit comments

Comments
 (0)