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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| # import library
from requests import get
from bs4 import BeautifulSoup as bs
import pandas as pd
from time import time
from time import sleep
from random import randint
from IPython.display import clear_output
from warnings import warn
import re
# declaration variables
SumNames = ["camarasama", "mefisto225", "Saber+Milena"]
SummonerName =[]
TotalRank = []
Tier_Rank = []
TierInfoLP = []
wins = []
losses = []
winratio = []
x = "+"
# creation of the loops
start_time = time()
requests = 0
# requests for the page
for name in SumNames:
response = get('http://euw.op.gg/summoner/userName='+ name)
# break between requests
sleep(randint(1,2))
# information about the requests
requests += 1
elapsed_time = time() - start_time
print('Request: {}; Frequency: {} requests/s'.format(requests, requests/elapsed_time))
clear_output(wait = True)
# if response != 200
if response.status_code != 200:
warn('Request: {}; Status code: {}'.format(requests, response.status_code))
break
# extract the page
page_html = bs(response.text, 'html.parser')
# select the summoner container information
summoners_infos = page_html.find_all('div', class_="tabItem")
SumName = name
if x in SumName:
SumName = SumName.replace(x, " ")
else:
continue
SumName.append(SummonerName)
# Retreiving Summoner information
#create loop to retreive information
for summoner_info in summoners_infos:
#extract the League Point
TierInfoLPs = page_html.find('span', class_="LeaguePoints").text
TierInfoLPs = re.sub('\s+', '', TierInfoLP)
TierInfoLPs = TierInfoLPs.replace("LP", "")
TierInfoLPs.append(TierInfoLP)
# extract the Total Rank
TotalRanks = page_html.find('span', class_="ranking").text
TotalRanks.append(TotalRank)
# extract the Tier Rank
Tier_Ranks = page_html.find('span', class_="tierRank").text
Tier_Ranks.append(Tier_Rank)
# extract the wins
win = page_html.find('span', class_="wins").text
win = win.replace("W", "")
win.append(wins)
# extract the losses
losse = page_html.find('span', class_="losses").text
losse = losse.replace("L", "")
losse.append(losses)
# extract the winratio
winratios = page_html.find('span', class_="winratio").text
winratios = winratio.replace("Win Ratio", "")
winratios.append(winratio)
#display Data
player_data = pd.DataFrame({
'Nom Invocateur': [SummonerName],
'Rank Total': [TotalRank],
'Helo': [Tier_Rank],
'Nbre de Points': [TierInfoLP],
'Nbre Victoire': [wins],
'Nbre Defaite': [losses],
'Ratio Victoire': [winratio]
})
print(player_data) |
Partager