Skip to content

Instantly share code, notes, and snippets.

@LaxWasHere
Created July 4, 2017 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LaxWasHere/aa659fd4c17bf37c7fc2060a70f7e00e to your computer and use it in GitHub Desktop.
Save LaxWasHere/aa659fd4c17bf37c7fc2060a70f7e00e to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import re
testurl = "https://play.eslgaming.com/team/members/{}/".format(input("Please enter a team Id: ")) #11430231
def main():
print("Members")
try:
req = requests.get(testurl, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'})
req.raise_for_status()
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
return "Could not find stats"
soup = BeautifulSoup(req.text, "lxml")
table = soup.find("table")
rows=list()
for row in table.findAll("div"):
for s in re.split("\t", row.text):
ns = s.rstrip("\n")
if "#" in ns and ns not in rows:
rows.append(ns)
i = 0
for players in rows:
rank = getRank(players)
i += int(rank)
print(players + " Rank:" + rank)
print("\nTeam Average: " + str(int(i / len(rows))))
def getRank(user):
url = "https://playoverwatch.com/en-us/career/pc/us/{}".format(user.replace("#","-"))
try:
req = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
req.raise_for_status()
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
return "Could not find stats " + str(e)
try:
soup = BeautifulSoup(req.text, "lxml")
stuff = soup.find_all(attrs={'class': 'u-align-center h6'})
return stuff[0].text
except IndexError:
return getRankOverbuff(user) #Use backup site if player has not played a game in the current season
def getRankOverbuff(user):
url = "https://www.overbuff.com/players/pc/{}".format(user.replace("#","-"))
try:
req = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
req.raise_for_status()
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e:
return "Could not find stats " + str(e)
try:
soup = BeautifulSoup(req.text, "lxml")
stuff = soup.find_all(attrs={'class': 'color-stat-rating'})
return stuff[0].text
except IndexError:
return str(0) #Return 0 if player has never played any competitive game
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment