Advertisement
Guest User

fantasyWebScrape

a guest
Apr 6th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.65 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.support.ui import WebDriverWait
  3. from selenium.webdriver.support import expected_conditions as EC
  4. from selenium.webdriver.common.by import By
  5.  
  6.  
  7. playingXIDict = []
  8. benchDict = []
  9.  
  10. def scrapePlayingXIPlayersInfo(xpathParm, tagName, statusOfPlayers):
  11. elements = driver.find_element_by_xpath(xpathParm)
  12. elementList = elements.find_elements_by_tag_name(tagName)
  13. for elem in elementList[1:]:
  14. print("elem text:",elem.text)
  15. print("elem text type:",type(elem.text))
  16. #splitString = elem.text.encode('utf-8').split()
  17. splitString = elem.text.encode('utf-8').decode("utf-8").split()
  18. print("splitString: ", splitString)
  19. data = {}
  20. data["PlayerName"] = splitString[0]
  21. data["Team"] = splitString[1]
  22. data["Points"] = splitString[2]
  23. data["MinutesPlayed"]= splitString[3]
  24. data["GoalScored"] = splitString[4]
  25. data["Assists"] = splitString[5]
  26. data["CleanSheets"] = splitString[6]
  27. data["GoalsConceded"] = splitString[7]
  28. data["OwnGoals"] = splitString[8]
  29. data["PenaltiesSaved"] = splitString[9]
  30. data["PenaltiesMissed"] = splitString[10]
  31. data["YellowCards"] = splitString[11]
  32. data["RedCards"] = splitString[12]
  33. data["Saves"] = splitString[13]
  34. data["Bonus"] = splitString[14]
  35. data["BonusPointSystem"] = splitString[15]
  36. data["Influence"] = splitString[16]
  37. data["Creativity"] = splitString[17]
  38. data["Threat"] = splitString[18]
  39. data["ICTIndex"] = splitString[19]
  40. playingXIDict.append(data)
  41. return playingXIDict
  42.  
  43. driver = webdriver.Chrome()
  44. driver.get("https://fantasy.premierleague.com/a/leagues/standings/123712/classic")
  45.  
  46.  
  47.  
  48. wait = WebDriverWait(driver, 10)
  49. wait.until(EC.presence_of_element_located((By.ID, 'ismr-classic-standings')))
  50.  
  51. driver.find_element_by_partial_link_text("Ryan").click()
  52.  
  53. wait = WebDriverWait(driver, 10)
  54. wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'List View')))
  55.  
  56. driver.find_element_by_partial_link_text('List View').click()
  57.  
  58.  
  59. playerXIOutput = scrapePlayingXIPlayersInfo("//*[@id=\"ismr-detail\"]/div/div[1]/div","tr","playingXI")
  60. print "Playing XI Dict: \n",playerXIOutput
  61.  
  62.  
  63.  
  64.  
  65.  
  66. Output:
  67. ('elem text:', u'Courtois\nCHE\n4 90 0 0 0 1 0 0 0 0 0 6 0 20 40 0 0 4')
  68. ('elem text type:', <type 'unicode'>)
  69. ('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'])
  70. ('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')
  71. ('elem text type:', <type 'unicode'>)
  72. ('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'])
  73. ('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')
  74. ('elem text type:', <type 'unicode'>)
  75. ('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'])
  76. ('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')
  77. ('elem text type:', <type 'unicode'>)
  78. ('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'])
  79. ('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')
  80. ('elem text type:', <type 'unicode'>)
  81. ('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'])
  82. ('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')
  83. ('elem text type:', <type 'unicode'>)
  84. ('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'])
  85. ('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')
  86. ('elem text type:', <type 'unicode'>)
  87. ('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'])
  88. ('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')
  89. ('elem text type:', <type 'unicode'>)
  90. ('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'])
  91. ('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')
  92. ('elem text type:', <type 'unicode'>)
  93. ('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'])
  94. ('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')
  95. ('elem text type:', <type 'unicode'>)
  96. ('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'])
  97. ('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')
  98. ('elem text type:', <type 'unicode'>)
  99. ('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'])
  100. Playing XI Dict:
  101. [{'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'}]
  102.  
  103. Problem: u'Ag\xfcero' printed instead of Agüero
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement