-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataExtraction2.py
More file actions
executable file
·45 lines (32 loc) · 1.07 KB
/
DataExtraction2.py
File metadata and controls
executable file
·45 lines (32 loc) · 1.07 KB
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
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 01 15:08:46 2018
@author: Dhairyya
"""
import urllib2
from bs4 import BeautifulSoup
url ="http://www.cricbuzz.com/cricket-series/2367/karnataka-premier-league-2015/matches"
page=urllib2.urlopen(url)
soup=BeautifulSoup(page)
#print soup.prettify()
file=open(r'C:\Users\Dhairyya\Desktop\IPL Data\kpl_2015.txt','w')
elems=soup.select(".text-hvr-underline")
#print type(elems)
#print len(elems)
pre="http://www.cricbuzz.com/live-cricket-scorecard"
elems=elems[:-2]
for elem in elems:
print elem.getText()
file.write(elem.getText()+'\n\n')
string=elem.get('href')
index= string.index('/',1)
url1=(pre+string[index:])
page1=urllib2.urlopen(url1)
soup1=BeautifulSoup(page1)
elems1=soup1.select(".cb-scrd-itms")
for elem1 in elems1:
string1=((elem1.getText()).encode("utf-8")).strip()
if(string1.startswith('Did not')==False and string1.startswith('Extras')==False):
file.write(string1+"\n")
file.write('\n')
file.close()