-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscrapCoupe.py
62 lines (46 loc) · 1.59 KB
/
scrapCoupe.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
from bs4 import BeautifulSoup
import requests, sys, getopt
##############################
# Récupération des arguments #
##############################
email = ''
password = ''
sys.argv.remove(sys.argv[0])
try:
opts, args = getopt.getopt(sys.argv, 'he:p:d:')
except getopt.GetoptError:
print('scrapCoupe.py -e <email> -p <password>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('scrapCoupe.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, 'remember': 'on'}
URLconnection = 'http://fantasy.sofoot.com/login.php'
session.post(URLconnection, data=payload)
#########################################
# Récupération des compétitions du jour #
#########################################
URLcompetitions = 'http://fantasy.sofoot.com/ajax_panel1.php'
ajaxMatches = session.get(URLcompetitions)
soup = BeautifulSoup(ajaxMatches.content, "lxml")
equipes_coupe = soup.find(class_="list-group-bordered").find_all(class_="list-group-item")
for equipe in equipes_coupe:
place = equipe.find('strong')
score = equipe.find(class_="badge")
name = equipe.find('a')
retour += place.string[:-1]+','+name.string+','+score.string[:-4]+'\n'
print(retour)
return retour
if __name__ == '__main__':
main(email, password)