-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrapMatches.py
79 lines (64 loc) · 2.54 KB
/
scrapMatches.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from bs4 import BeautifulSoup
import requests, sys, getopt, time
##############################
# Recuperation des arguments #
##############################
email = ''
password = ''
requestedDate = time.strftime("%Y-%m-%d")
# Par defaut date du jour
sys.argv.remove(sys.argv[0])
try:
opts, args = getopt.getopt(sys.argv, 'he:p:d:')
except getopt.GetoptError:
print('scrapMatches.py -e <email> -p <password> -d <date>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('scrapMatches.py -e <email> -p <password> -d <date>')
sys.exit()
elif opt == '-e':
email = arg
elif opt == '-p':
password = arg
elif opt == '-d':
requestedDate = arg
def main(_email, _password, _requesteddate):
retour = ""
####################
# Authentification #
####################
session = requests.Session()
payload = {'email': _email, 'password': _password, 'remember': 'on'}
URLconnection = 'http://fantasy.sofoot.com/login.php'
session.post(URLconnection, data=payload)
#########################################
# Recuperation des competitions du jour #
#########################################
URLcompetitions = 'http://fantasy.sofoot.com/ajax_panel2.php?date=' + _requesteddate
ajaxMatches = session.get(URLcompetitions)
soup = BeautifulSoup(ajaxMatches.content, "lxml")
competitions = soup.find_all(class_="nom-competition-pick")
for competition in competitions :
URLmatches = "http://fantasy.sofoot.com/ajax_panel3.php?competition=" + competition.string
ajaxMatches = session.get(URLmatches)
soupMatches = BeautifulSoup(ajaxMatches.content, "lxml")
teams = soupMatches.find_all(class_="nom-pick-seul")
cotes = soupMatches.find_all("b")
scores = soupMatches.find_all(class_="ribbon-inner")
i = 0
while i < len(teams):
if not scores:
retour+=(competition.string + ','
+ teams[i].string + ',' + cotes[i].string + ','
+ teams[i + 1].string + ',' + cotes[i + 1].string + '\n')
i += 2
else :
retour += (competition.string + ','
+ teams[i].string + ',' + cotes[i].string + ',' + scores[i].string[:-4] + ','
+ teams[i + 1].string + ',' + cotes[i + 1].string + ',' + scores[i+1].string[:-4] + '\n')
i += 2
print(retour)
return retour
if __name__ == '__main__':
main(email, password, requestedDate)