Created
July 11, 2015 18:17
-
-
Save danker/8cb65519a5384f5f20fd to your computer and use it in GitHub Desktop.
Scrape the LoL eSports site to get current NA LCS Rankings. (A simple script to test web-scraping in Python)
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
import requests | |
from bs4 import BeautifulSoup | |
import time | |
url_to_scrape = 'http://na.lolesports.com/na-lcs/2015/summer/standings' | |
r = requests.get(url_to_scrape) | |
# parse the text of the URL | |
soup = BeautifulSoup(r.text, "html.parser") | |
# get the "stats-container" table | |
stats_table = soup.find("table", class_="stats-container") | |
# Each row is: Rank/Team/Wins/Losses | |
format_string = "%-4s %-20s %-s %-s" | |
print "Current NA LCS STANDINGS" | |
print "-----------------------------" | |
print format_string % ("RANK", "TEAM", "W", "L") | |
for row in stats_table.find_all("tr"): | |
cells = row.find_all("td") | |
if len(cells) > 0: | |
print (format_string % (cells[0].text.strip(), cells[2].text.strip(), cells[3].text.strip(), cells[4].text.strip())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment