-
Notifications
You must be signed in to change notification settings - Fork 0
/
mudrik.py
39 lines (30 loc) · 1.01 KB
/
mudrik.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
from urllib.request import urlopen
from bs4 import BeautifulSoup
import csv
from datetime import datetime
def writecsv(data):
date = datetime.now().strftime('%Y-%m-%d')
with open('excsv.csv','a',newline='',encoding='utf-8') as file:
filewriter = csv.writer(file)
filewriter.writerow(data)
alldata = {}
def footballtable(season):
url = 'https://www.sanook.com/sport/football/table/premierleague/20'+ str(season) + '-20' + str(season + 1) + '/'
webopen = urlopen(url)
html_page = webopen.read()
webopen.close()
data = BeautifulSoup(html_page,'html.parser')
try:
team = data.find('td',{"class":"jsx-827658710"})
year = data.find('h1',{"class":"jsx-1187604094"})
champ = team.text.strip()
year = year.text
alldata[champ] = year
except:
pass
for i in range(10,20):
footballtable(i)
for k,v in alldata.items():
data = [k,v]
writecsv(data)
print('save')