-
Notifications
You must be signed in to change notification settings - Fork 9
/
leagues.py
25 lines (23 loc) · 909 Bytes
/
leagues.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
import requests
import re
import json
from info import leagues
from lxml import html
s = requests.Session()
for league in leagues:
page = s.get('http://www.oddsportal.com/soccer' + league[0])
tree = html.fromstring(page.text)
i = 0
ids = []
for a in tree.xpath('//ul[@class="main-filter"]//a'):
if 'results' in a.attrib['href']:
result = s.get('http://www.oddsportal.com' + a.attrib['href'])
id = re.findall(r'id":"([^"]+)"', result.text)[0]
t = html.fromstring(result.text)
season = t.xpath('//div[@class="main-menu2 main-menu-gray"]//span[@class="active"]//a')[0].text_content()
beka = [id, season, a.attrib['href'].replace('/results/', '')]
if beka not in ids:
ids.append(beka)
print(a.attrib['href'].replace('/results/', ''))
league.append(ids)
print(json.dumps(leagues))