Created
September 17, 2017 05:43
-
-
Save bishk/2f8ed60d5c8c621946f706fd1378268b to your computer and use it in GitHub Desktop.
Futhead parsing
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
from bs4 import BeautifulSoup | |
import requests | |
import sets | |
import sys | |
#reload(sys) | |
#sys.setdefaultencoding('utf-8') | |
players = [] #with all players | |
for i in range(1, 17): | |
address = "http://www.futhead.com/18/players/?level=gold&page=" + str(i) + "&bin_platform=ps" | |
r = requests.get(address) | |
data = r.text | |
soup = BeautifulSoup(data, 'html.parser') | |
ratings = soup.findAll('span', 'player-rating') | |
names = soup.findAll('span', 'player-name') | |
position = soup.findAll('span', 'player-club-league-name') | |
stats = soup.findAll('span', 'player-stat') | |
number = len(ratings) | |
for j in range(number): | |
#print u'\xe9' | |
player = dict() | |
player["name"] = names[j].text.encode("utf8") | |
b = position[j].text | |
c = ("".join(b.split())) | |
for x in range(len(c)): | |
if (c[x] == '|'): | |
for y in range(x+1, len(c)): | |
if (c[y] == '|'): | |
player["pos"] = (c[:x].encode("utf8")) | |
player["club"] = (c[x+1:y].encode("utf8")) | |
player["league"] = (c[y+1:].encode("utf8")) | |
player["rating"] = (int(ratings[j].text)) | |
for k in range(0, 6): | |
#print stats[12*j+k].text.encode("utf8") | |
if (k == 0): | |
player["pace"] = int(stats[12*j+k].text.encode("utf8")[:2]) | |
if (k == 1): | |
player["shoot"] = int(stats[12*j+k].text.encode("utf8")[:2]) | |
if (k == 2): | |
player["pass"] = int(stats[12*j+k].text.encode("utf8")[:2]) | |
if (k == 3): | |
player["dribble"] = int(stats[12*j+k].text.encode("utf8")[:2]) | |
if (k == 4): | |
player["def"] = int(stats[12*j+k].text.encode("utf8")[:2]) | |
if (k == 5): | |
player["phy"] = int(stats[12*j+k].text.encode("utf8")[:2]) | |
players.append(player) | |
print player | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment