La solution
Il faut installer le module BeautifulSoup4 :
$ sudo pip3 install BeautifulSoup4
Le code est alors :
01: from urllib.request import urlopen
02: from bs4 import BeautifulSoup
03: import csv
04:
05: if __name__ == '__main__':
06: url = 'http://www.lfp.fr/ligue1/classement'
07: page = urlopen(url)
08: soup = BeautifulSoup(page, 'html.parser')
09: ligue_1 = []
10:
11: classement = soup.find('table')
12: clubs = classement.findAll('tr')
13:
14: for club in clubs:
15: data = []
16:
17: nom = club.find('td', attrs={'class' : 'club'})
18: if nom:
19: data.append(nom.find('a').text.strip())
20: else:
21: continue
22:
23: position = club.find('td', attrs={'class' : 'position'})
24: if position:
25: data.append(position.text.strip())
26: else:
27: data.append('-')
28:
29: diff = club.find('td', attrs={'class' : 'diff'})
30: if diff:
31: ...
- Accédez à tous les contenus de Connect en illimité
- Découvrez des listes de lecture et des contenus Premium
- Consultez les nouveaux articles en avant-première