-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbowling.py
70 lines (65 loc) · 2.31 KB
/
bowling.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
import csv
import lxml.html
url1='http://stats.espncricinfo.com/ci/engine/stats/index.html?class=1;orderby=start;'
url2 ='page='
url3 ='template=results;type=bowling;view=innings'
url5 = ['http://stats.espncricinfo.com/ci/engine/stats/index.html?class=1;orderby=start;template=results;type=bowling;view=innings']
for i in range(2,1717):
url4 = url1 + url2 + str(i) + ';' + url3
url5.append(url4)
out = csv.writer(open('test_bowl.csv','wb',))
out.writerow(('Player', 'Country', 'Overs','BPO','Mdns', 'Runs','Wkts','Econ','Inns','Opposition','Ground','Start Date'))
for page in url5:
Player = []
country = []
Overs = []
BPO = []
Mdns = []
Runs = []
Wkts=[]
Econ = []
innings = []
opposition = []
ground = []
startdate = []
content = lxml.html.parse(page)
Playe = content.xpath('//tr[@class="data1"]/td[1]/a')
countr = content.xpath('//tr[@class="data1"]/td[1]/*')
Over = content.xpath('//tr[@class="data1"]/td[2]')
BP = content.xpath('//tr[@class="data1"]/td[3]')
Mdn = content.xpath('//tr[@class="data1"]/td[4]')
Run = content.xpath('//tr[@class="data1"]/td[5]')
Wkt = content.xpath('//tr[@class="data1"]/td[6]')
Eco = content.xpath('//tr[@class="data1"]/td[7]')
inns = content.xpath('//tr[@class="data1"]/td[8]')
oppos = content.xpath('//tr[@class="data1"]/td[10]/a')
grou = content.xpath('//tr[@class="data1"]/td[11]/a')
std = content.xpath('//tr[@class="data1"]/td[12]/b')
Play = [bat.text for bat in Playe]
cou = [c.tail for c in countr]
Ove = [r.text for r in Over]
B = [mint.text for mint in BP]
Md = [bfaced.text for bfaced in Mdn]
Ru = [fs.text for fs in Run]
Wk = [s.text for s in Wkt]
Ec = [srt.text for srt in Eco]
inngs = [inn.text for inn in inns]
opps = [opp.text for opp in oppos]
grnd = [gr.text for gr in grou]
sdate = [sd.text for sd in std]
Player.extend(Play)
country.extend(cou)
Overs.extend(Ove)
BPO.extend(B)
Mdns.extend(Md)
Runs.extend(Ru)
Wkts.extend(Wk)
Econ.extend(Ec)
innings.extend(inngs)
opposition.extend(opps)
ground.extend(grnd)
startdate.extend(sdate)
zipped = zip(Player,country,Overs,BPO,Mdns,Runs,Wkts,Econ,innings,opposition,ground,startdate)
for row in zipped:
out.writerow(row)
zipped = None