Created
September 23, 2016 05:56
-
-
Save kadnan/277d1fa84327710fb82d530f20457b3d to your computer and use it in GitHub Desktop.
Fetching, parsing and cleaning Pakistan England Test data from Cricinfo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This will grab the data from CricInfo Site about TestMatch Played by Pakistan against England from 1954-till now | |
""" | |
import requests | |
from bs4 import BeautifulSoup | |
url = 'http://stats.espncricinfo.com/ci/engine/team/7.html?class=1;opposition=1;template=results;type=team;view=results' | |
r = requests.get(url) | |
html = r.text | |
#create soup object | |
soup = BeautifulSoup(html,'lxml') | |
recs = soup.select('tbody > .data1') | |
file = open('data_england_test.csv', "w") | |
for i in range(2,len(recs)): | |
single = recs[i].findAll('td') | |
file.write(single[0].text + ','+single[1].text+ ','+single[2].text+ ','+single[3].text+ ','+ single[4].text+ ','+single[6].text+ ','+ single[7].text+'\n') | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think at line 18, the index you are looking for is single[5] and not single[4] as it is empty.