-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
22 lines (18 loc) · 800 Bytes
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from selenium import webdriver
import lxml.html as lh
from decouple import config
browser = webdriver.Safari()
browser.get(config('LINK'))
innerHTML = browser.execute_script("return document.body.innerHTML")
browser.quit()
tree = lh.fromstring(innerHTML)
righe = tree.xpath('//*[@id="ranking"]/table/tbody/tr')
classifica = [['Team', 'Points', 'Match Played', 'Wins', 'Draws', 'Loses', 'Goal Made', 'Goal Taken', 'Goal difference']]
for riga in righe:
secondo = [item.text_content().replace("\n", "") for item in riga.xpath('td')]
classifica.append([i for i in secondo if i])
s = [[str(e) for e in row] for row in classifica]
lens = [max(map(len, col)) for col in zip(*s)]
fmt = '\t'.join('{{:{}}}'.format(x) for x in lens)
table = [fmt.format(*row) for row in s]
print ('\n'.join(table))