In [2]:
library(XML)
url="http://stats.espncricinfo.com/ci/engine/stats/index.html?class=1;team=8;template=results;type=batting"
#Note I can also break the url string and use paste command to modify this url with parameters
tables=readHTMLTable(url)
tables$"Overall figures"
Out[2]:
PlayerSpanMatInnsNORunsHSAve100500
1KC Sangakkara2000-2015134233171240031957.40385211
2DPMD Jayawardene1997-2014149252151181437449.84345015
3ST Jayasuriya1991-200711018814697334040.07143115
4PA de Silva1984-20029315911636126742.9720227
5MS Atapattu1990-20079015615550224939.02161722
6TM Dilshan1999-20138714511549219340.98162314
7TT Samaraweera2001-20138113220546223148.76143011
8A Ranatunga1982-200093155125105135*35.6943812
9HP Tillakaratne1989-200483131254545204*42.8711209
10AD Mathews2009-2015569717401516050.187231
11WPUJC Vaas1994-2009111162353089100*24.3211312
12RS Mahanama1986-199852891257622529.274117
13AP Gurusinha1985-199641707245214338.92783
14HAPW Jayawardene2000-20155883112124154*29.50459
15RS Kaluwitharana1992-2004497841933132*26.12395
16LD Chandimal2011-2015254441835162*45.875101
17RP Arnold1997-200444694182112328.013107
18NT Paranavitana2009-201232605179211132.582119
19FDM Karunaratne2012-201525482162218635.26375
20JK Silva2011-201524440140413931.90294
21LRD Mendis1982-198824431132912431.64482
22RL Dias1982-198720361128510936.71382
23UC Hathurusingha1991-19992644112748329.62082
24M Muralitharan1992-20101321625612596711.870132
25S Wettimuny1982-198723431122119029.07265
26MG Vandort2001-200820332114414036.90443
27WU Tharanga2005-201521381111716530.18155
28HMRKB Herath1999-2015679922104980*13.620118
29RS Madugalle1982-198821394102910329.40174
30HDRL Thirimanne2011-201523456969155*24.84146
31HDPK Dharmasena1993-20043151786862*19.72034
32SM Warnapura2007-20091424182112035.69275
33JR Ratnayeke1982-1989223868079325.21055
34UDU Chandana1999-2005162416169226.78020
35MF Maharoof2004-2011223445567218.53031
36GP Wickramasinghe1991-200140645555519.400117
37LPC Silva2006-200811171537152*33.56123
38S Ranatunga1994-1997917153111833.18221
39KTGD Prasad2008-2015253924764712.86008
40RJ Ratnayake1983-1992233664335614.43025
41CK Kapugedera2006-200981534189634.83041
42DS de Silva1982-1984122234066121.36023
43KMDN Kulasekara2005-2014212813916414.48014
44J Mubarak2002-2015132313854917.50005
45KDK Vithanage2013-201510162370103*26.42111
46SAR Silva1983-1988916235311125.21201
47ALF de Mel1982-1986172853263414.17005
48DSBP Kuruppu1987-1991471320201*53.33100
49RS Kalpage1993-1999111822946318.37020
50DNT Zoysa1997-20043040628828*8.47009
In [1]:
from bs4 import BeautifulSoup
import urllib
In [16]:
r = urllib.urlopen("http://stats.espncricinfo.com/ci/engine/stats/index.html?class=1;team=8;template=results;type=batting").read()
soup = BeautifulSoup(r, "lxml")
headings=[row.get_text().encode("utf-8") for row in soup.find_all("th")]

datasets = []
for row in soup.find_all("tr"):
    
    data=[]
    for td in row.find_all("td"):
        data.append(td.get_text().encode("utf-8"))
    if len(data)==12:
        datasets.append(data)

    
In [26]:
import numpy as np
import pandas as pd
table=pd.DataFrame(np.array(datasets),columns=headings)
print table
               Player       Span  Mat Inns  NO   Runs    HS    Ave 100  50  \
0       KC Sangakkara  2000-2015  134  233  17  12400   319  57.40  38  52   
1    DPMD Jayawardene  1997-2014  149  252  15  11814   374  49.84  34  50   
2       ST Jayasuriya  1991-2007  110  188  14   6973   340  40.07  14  31   
3         PA de Silva  1984-2002   93  159  11   6361   267  42.97  20  22   
4         MS Atapattu  1990-2007   90  156  15   5502   249  39.02  16  17   
5          TM Dilshan  1999-2013   87  145  11   5492   193  40.98  16  23   
6      TT Samaraweera  2001-2013   81  132  20   5462   231  48.76  14  30   
7         A Ranatunga  1982-2000   93  155  12   5105  135*  35.69   4  38   
8     HP Tillakaratne  1989-2004   83  131  25   4545  204*  42.87  11  20   
9          AD Mathews  2009-2015   56   97  17   4015   160  50.18   7  23   
10         WPUJC Vaas  1994-2009  111  162  35   3089  100*  24.32   1  13   
11        RS Mahanama  1986-1998   52   89   1   2576   225  29.27   4  11   
12       AP Gurusinha  1985-1996   41   70   7   2452   143  38.92   7   8   
13   HAPW Jayawardene  2000-2015   58   83  11   2124  154*  29.50   4   5   
14   RS Kaluwitharana  1992-2004   49   78   4   1933  132*  26.12   3   9   
15       LD Chandimal  2011-2015   25   44   4   1835  162*  45.87   5  10   
16          RP Arnold  1997-2004   44   69   4   1821   123  28.01   3  10   
17    NT Paranavitana  2009-2012   32   60   5   1792   111  32.58   2  11   
18    FDM Karunaratne  2012-2015   25   48   2   1622   186  35.26   3   7   
19           JK Silva  2011-2015   24   44   0   1404   139  31.90   2   9   
20         LRD Mendis  1982-1988   24   43   1   1329   124  31.64   4   8   
21            RL Dias  1982-1987   20   36   1   1285   109  36.71   3   8   
22   UC Hathurusingha  1991-1999   26   44   1   1274    83  29.62   0   8   
23     M Muralitharan  1992-2010  132  162  56   1259    67  11.87   0   1   
24        S Wettimuny  1982-1987   23   43   1   1221   190  29.07   2   6   
25         MG Vandort  2001-2008   20   33   2   1144   140  36.90   4   4   
26        WU Tharanga  2005-2015   21   38   1   1117   165  30.18   1   5   
27       HMRKB Herath  1999-2015   67   99  22   1049   80*  13.62   0   1   
28       RS Madugalle  1982-1988   21   39   4   1029   103  29.40   1   7   
29    HDRL Thirimanne  2011-2015   23   45   6    969  155*  24.84   1   4   
30    HDPK Dharmasena  1993-2004   31   51   7    868   62*  19.72   0   3   
31       SM Warnapura  2007-2009   14   24   1    821   120  35.69   2   7   
32       JR Ratnayeke  1982-1989   22   38   6    807    93  25.21   0   5   
33       UDU Chandana  1999-2005   16   24   1    616    92  26.78   0   2   
34        MF Maharoof  2004-2011   22   34   4    556    72  18.53   0   3   
35  GP Wickramasinghe  1991-2001   40   64   5    555    51   9.40   0   1   
36          LPC Silva  2006-2008   11   17   1    537  152*  33.56   1   2   
37        S Ranatunga  1994-1997    9   17   1    531   118  33.18   2   2   
38        KTGD Prasad  2008-2015   25   39   2    476    47  12.86   0   0   
39       RJ Ratnayake  1983-1992   23   36   6    433    56  14.43   0   2   
40      CK Kapugedera  2006-2009    8   15   3    418    96  34.83   0   4   
41        DS de Silva  1982-1984   12   22   3    406    61  21.36   0   2   
42    KMDN Kulasekara  2005-2014   21   28   1    391    64  14.48   0   1   
43          J Mubarak  2002-2015   13   23   1    385    49  17.50   0   0   
44      KDK Vithanage  2013-2015   10   16   2    370  103*  26.42   1   1   
45          SAR Silva  1983-1988    9   16   2    353   111  25.21   2   0   
46         ALF de Mel  1982-1986   17   28   5    326    34  14.17   0   0   
47       DSBP Kuruppu  1987-1991    4    7   1    320  201*  53.33   1   0   
48         RS Kalpage  1993-1999   11   18   2    294    63  18.37   0   2   
49          DNT Zoysa  1997-2004   30   40   6    288   28*   8.47   0   0   

     0    
0   11    
1   15    
2   15    
3    7    
4   22    
5   14    
6   11    
7   12    
8    9    
9    1    
10  12    
11   7    
12   3    
13   9    
14   5    
15   1    
16   7    
17   9    
18   5    
19   4    
20   2    
21   2    
22   2    
23  32    
24   5    
25   3    
26   5    
27  18    
28   4    
29   6    
30   4    
31   5    
32   5    
33   0    
34   1    
35  17    
36   3    
37   1    
38   8    
39   5    
40   1    
41   3    
42   4    
43   5    
44   1    
45   1    
46   5    
47   0    
48   0    
49   9    
In [ ]: