-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrapTeamResults.py
64 lines (49 loc) · 1.55 KB
/
scrapTeamResults.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
from bs4 import BeautifulSoup
import requests, sys, getopt
from util.html_table_parser import HTMLTableParser
##############################
# Récupération des arguments #
##############################
email = ''
password = ''
sys.argv.remove(sys.argv[0])
try:
opts, args = getopt.getopt(sys.argv, 'he:p:')
except getopt.GetoptError:
print('scrapTeamResults.py -e <email> -p <password>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('scrapTeamResults.py -e <email> -p <password>')
sys.exit()
elif opt == '-e':
email = arg
elif opt == '-p':
password = arg
def main(_email, _password):
retour = ""
####################
# Authentification #
####################
session = requests.Session()
payload = {'email': _email, 'password': _password}
URLconnection = 'http://fantasy.sofoot.com/login.php'
r = session.post(URLconnection, data=payload)
#########################################
# Récupération des compétitions du jour #
#########################################
URLteam = 'http://fantasy.sofoot.com/?tpl=team'
ajaxTeam = session.get(URLteam)
soup = BeautifulSoup(ajaxTeam.content, "lxml")
teamLines = str(soup.find("table"))
p = HTMLTableParser()
p.feed(teamLines)
i=2
while i < len(p.tables[0]):
result = p.tables[0][i][4].split("(")
retour += p.tables[0][i][1]+","+result[0][:-1]+","+result[1][:-5]+"\n"
i+=1
print(retour)
return retour
if __name__ == '__main__':
main(email, password)