Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.common.by import By
- playingXIDict = []
- benchDict = []
- def scrapePlayingXIPlayersInfo(xpathParm, tagName, statusOfPlayers):
- elements = driver.find_element_by_xpath(xpathParm)
- elementList = elements.find_elements_by_tag_name(tagName)
- for elem in elementList[1:]:
- print("elem text:",elem.text)
- print("elem text type:",type(elem.text))
- #splitString = elem.text.encode('utf-8').split()
- splitString = elem.text.encode('utf-8').decode("utf-8").split()
- print("splitString: ", splitString)
- data = {}
- data["PlayerName"] = splitString[0]
- data["Team"] = splitString[1]
- data["Points"] = splitString[2]
- data["MinutesPlayed"]= splitString[3]
- data["GoalScored"] = splitString[4]
- data["Assists"] = splitString[5]
- data["CleanSheets"] = splitString[6]
- data["GoalsConceded"] = splitString[7]
- data["OwnGoals"] = splitString[8]
- data["PenaltiesSaved"] = splitString[9]
- data["PenaltiesMissed"] = splitString[10]
- data["YellowCards"] = splitString[11]
- data["RedCards"] = splitString[12]
- data["Saves"] = splitString[13]
- data["Bonus"] = splitString[14]
- data["BonusPointSystem"] = splitString[15]
- data["Influence"] = splitString[16]
- data["Creativity"] = splitString[17]
- data["Threat"] = splitString[18]
- data["ICTIndex"] = splitString[19]
- playingXIDict.append(data)
- return playingXIDict
- driver = webdriver.Chrome()
- driver.get("https://fantasy.premierleague.com/a/leagues/standings/123712/classic")
- wait = WebDriverWait(driver, 10)
- wait.until(EC.presence_of_element_located((By.ID, 'ismr-classic-standings')))
- driver.find_element_by_partial_link_text("Ryan").click()
- wait = WebDriverWait(driver, 10)
- wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'List View')))
- driver.find_element_by_partial_link_text('List View').click()
- playerXIOutput = scrapePlayingXIPlayersInfo("//*[@id=\"ismr-detail\"]/div/div[1]/div","tr","playingXI")
- print "Playing XI Dict: \n",playerXIOutput
- Output:
- ('elem text:', u'Courtois\nCHE\n4 90 0 0 0 1 0 0 0 0 0 6 0 20 40 0 0 4')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Courtois', u'CHE', u'4', u'90', u'0', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'6', u'0', u'20', u'40', u'0', u'0', u'4'])
- ('elem text:', u'Alonso\nCHE\n2 90 0 0 0 1 0 0 0 0 0 0 0 11 11 10.7 0 2.2')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Alonso', u'CHE', u'2', u'90', u'0', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'0', u'0', u'11', u'11', u'10.7', u'0', u'2.2'])
- ('elem text:', u'Walker\nTOT\n2 90 0 0 0 1 0 0 0 0 0 0 0 7 5 14.6 15 3.5')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Walker', u'TOT', u'2', u'90', u'0', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'0', u'0', u'7', u'5', u'14.6', u'15', u'3.5'])
- ('elem text:', u'Baines\nEVE\n2 90 0 0 0 1 0 0 0 0 0 0 0 8 8.8 1.8 4 1.5')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Baines', u'EVE', u'2', u'90', u'0', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'0', u'0', u'8', u'8.8', u'1.8', u'4', u'1.5'])
- ('elem text:', u'Son\nTOT\n7 90 1 0 0 1 0 0 0 0 0 0 0 19 37.2 13.3 76 12.7')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Son', u'TOT', u'7', u'90', u'1', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'0', u'0', u'19', u'37.2', u'13.3', u'76', u'12.7'])
- ('elem text:', u'King\nBOU\n7 90 1 0 0 2 0 0 0 0 0 0 0 24 38.4 1 23 6.2')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'King', u'BOU', u'7', u'90', u'1', u'0', u'0', u'2', u'0', u'0', u'0', u'0', u'0', u'0', u'0', u'24', u'38.4', u'1', u'23', u'6.2'])
- ('elem text:', u'Zaha\nCRY\n2 90 0 0 0 3 0 0 0 0 0 0 0 1 0 1.5 28 2.7')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Zaha', u'CRY', u'2', u'90', u'0', u'0', u'0', u'3', u'0', u'0', u'0', u'0', u'0', u'0', u'0', u'1', u'0', u'1.5', u'28', u'2.7'])
- ('elem text:', u'Davies\nEVE\n1 90 0 0 0 1 0 0 0 1 0 0 0 0 0 7.4 12 1.7')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Davies', u'EVE', u'1', u'90', u'0', u'0', u'0', u'1', u'0', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'7.4', u'12', u'1.7'])
- ('elem text:', u'Ibrahimovic\nMUN\n7 90 1 0 0 1 0 0 0 0 0 0 1 23 34.8 7.2 65 10.7')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Ibrahimovic', u'MUN', u'7', u'90', u'1', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'0', u'1', u'23', u'34.8', u'7.2', u'65', u'10.7'])
- ('elem text:', u'Lukaku\nEVE\n2 90 0 0 0 1 0 0 0 0 0 0 0 4 9 3.6 59 7.2')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Lukaku', u'EVE', u'2', u'90', u'0', u'0', u'0', u'1', u'0', u'0', u'0', u'0', u'0', u'0', u'0', u'4', u'9', u'3.6', u'59', u'7.2'])
- ('elem text:', u'Ag\xfcero\nMCI\n8 90 1 0 0 2 0 0 0 0 0 0 2 26 41.4 18.5 89 14.9')
- ('elem text type:', <type 'unicode'>)
- ('splitString: ', [u'Ag\xfcero', u'MCI', u'8', u'90', u'1', u'0', u'0', u'2', u'0', u'0', u'0', u'0', u'0', u'0', u'2', u'26', u'41.4', u'18.5', u'89', u'14.9'])
- Playing XI Dict:
- [{'GoalsConceded': u'1', 'Bonus': u'0', 'Threat': u'0', 'PlayerName': u'Courtois', 'BonusPointSystem': u'20', 'Creativity': u'0', 'Saves': u'6', 'Influence': u'40', 'GoalScored': u'0', 'Points': u'4', 'CleanSheets': u'0', 'ICTIndex': u'4', 'PenaltiesSaved': u'0', 'Team': u'CHE', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'1', 'Bonus': u'0', 'Threat': u'0', 'PlayerName': u'Alonso', 'BonusPointSystem': u'11', 'Creativity': u'10.7', 'Saves': u'0', 'Influence': u'11', 'GoalScored': u'0', 'Points': u'2', 'CleanSheets': u'0', 'ICTIndex': u'2.2', 'PenaltiesSaved': u'0', 'Team': u'CHE', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'1', 'Bonus': u'0', 'Threat': u'15', 'PlayerName': u'Walker', 'BonusPointSystem': u'7', 'Creativity': u'14.6', 'Saves': u'0', 'Influence': u'5', 'GoalScored': u'0', 'Points': u'2', 'CleanSheets': u'0', 'ICTIndex': u'3.5', 'PenaltiesSaved': u'0', 'Team': u'TOT', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'1', 'Bonus': u'0', 'Threat': u'4', 'PlayerName': u'Baines', 'BonusPointSystem': u'8', 'Creativity': u'1.8', 'Saves': u'0', 'Influence': u'8.8', 'GoalScored': u'0', 'Points': u'2', 'CleanSheets': u'0', 'ICTIndex': u'1.5', 'PenaltiesSaved': u'0', 'Team': u'EVE', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'1', 'Bonus': u'0', 'Threat': u'76', 'PlayerName': u'Son', 'BonusPointSystem': u'19', 'Creativity': u'13.3', 'Saves': u'0', 'Influence': u'37.2', 'GoalScored': u'1', 'Points': u'7', 'CleanSheets': u'0', 'ICTIndex': u'12.7', 'PenaltiesSaved': u'0', 'Team': u'TOT', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'2', 'Bonus': u'0', 'Threat': u'23', 'PlayerName': u'King', 'BonusPointSystem': u'24', 'Creativity': u'1', 'Saves': u'0', 'Influence': u'38.4', 'GoalScored': u'1', 'Points': u'7', 'CleanSheets': u'0', 'ICTIndex': u'6.2', 'PenaltiesSaved': u'0', 'Team': u'BOU', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'3', 'Bonus': u'0', 'Threat': u'28', 'PlayerName': u'Zaha', 'BonusPointSystem': u'1', 'Creativity': u'1.5', 'Saves': u'0', 'Influence': u'0', 'GoalScored': u'0', 'Points': u'2', 'CleanSheets': u'0', 'ICTIndex': u'2.7', 'PenaltiesSaved': u'0', 'Team': u'CRY', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'1', 'Bonus': u'0', 'Threat': u'12', 'PlayerName': u'Davies', 'BonusPointSystem': u'0', 'Creativity': u'7.4', 'Saves': u'0', 'Influence': u'0', 'GoalScored': u'0', 'Points': u'1', 'CleanSheets': u'0', 'ICTIndex': u'1.7', 'PenaltiesSaved': u'0', 'Team': u'EVE', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'1', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'1', 'Bonus': u'1', 'Threat': u'65', 'PlayerName': u'Ibrahimovic', 'BonusPointSystem': u'23', 'Creativity': u'7.2', 'Saves': u'0', 'Influence': u'34.8', 'GoalScored': u'1', 'Points': u'7', 'CleanSheets': u'0', 'ICTIndex': u'10.7', 'PenaltiesSaved': u'0', 'Team': u'MUN', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'1', 'Bonus': u'0', 'Threat': u'59', 'PlayerName': u'Lukaku', 'BonusPointSystem': u'4', 'Creativity': u'3.6', 'Saves': u'0', 'Influence': u'9', 'GoalScored': u'0', 'Points': u'2', 'CleanSheets': u'0', 'ICTIndex': u'7.2', 'PenaltiesSaved': u'0', 'Team': u'EVE', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}, {'GoalsConceded': u'2', 'Bonus': u'2', 'Threat': u'89', 'PlayerName': u'Ag\xfcero', 'BonusPointSystem': u'26', 'Creativity': u'18.5', 'Saves': u'0', 'Influence': u'41.4', 'GoalScored': u'1', 'Points': u'8', 'CleanSheets': u'0', 'ICTIndex': u'14.9', 'PenaltiesSaved': u'0', 'Team': u'MCI', 'OwnGoals': u'0', 'RedCards': u'0', 'PenaltiesMissed': u'0', 'Assists': u'0', 'YellowCards': u'0', 'MinutesPlayed': u'90'}]
- Problem: u'Ag\xfcero' printed instead of Agüero
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement