-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayerData.py
68 lines (50 loc) · 1.63 KB
/
playerData.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
import urllib
import json
from bs4 import BeautifulSoup
from bs4 import element
import xml.etree.ElementTree as ET
from pymongo import MongoClient
client = MongoClient()
db = client.cricket
firstName = ""
lastName = ""
def getPlayerName(playerSoup):
matches = playerSoup.select(".playerBio h1")
firstName = list(matches[0].descendants)[0].string.strip()
lastName = list(matches[0].descendants)[1].string.strip()
print("Player: "+firstName+" "+lastName)
def getPlayerstats(playerSoup):
matches = playerSoup.select(".unitContent > div")
print matches
# for child in matches[0].descendants:
# print child
for i in range(1000,10000):
#changingurl = "http://www.iplt20.com/teams/royal-challengers-bangalore/squad/"+str(i)+"/chris-gayle"
flag =0
changingurl = "http://dynamic.pulselive.com/dynamic/data/core/cricket/careerStats/"+str(i)+"_careerStats.js?_1397772296778="
try:
sock = urllib.urlopen(changingurl)
except Exception:
pass
htmlSource = sock.read()
htmlSource = htmlSource[20:len(htmlSource)-2]
try:
decoded = json.loads(htmlSource)
except:
flag = 1
if flag == 0:
fo = open("./players/player"+str(i)+".txt", "wb")
fo.write(htmlSource);
fo.close()
print decoded['player']['fullName']
# for i in decoded['stats']:
# if i['matchType'] == "IPLT20":
# print i['battingStats']
sock.close()
soup = BeautifulSoup(htmlSource)
if "Error 404 - Page not found." in (soup.get_text()):
pass
else:
#getPlayerName(soup)
#getPlayerstats(soup)
pass