Last active
April 12, 2016 06:13
-
-
Save sjsakib/7a4d2323267da43d6fff8115490b2e66 to your computer and use it in GitHub Desktop.
A python script that fetches Code Jam 2016 Bangladeshi participants' handle, rank and point from the qualification round scoreboard. Needs selenium and chromedriver
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
#encoding: utf-8 | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
def get_text(driver,element): #could be done without this ugly funcion. didn't know | |
return driver.execute_script(""" | |
return arguments[0].firstChild.textContent; | |
""", element) | |
driver = webdriver.Chrome() | |
driver.get("https://code.google.com/codejam/contest/6254486/scoreboard") | |
file = open("Jammers","w") | |
file.write("#".ljust(5)+"Rank".ljust(7)+"Handle".ljust(30)+"Points".ljust(6)+"\n") | |
file.write("-"*48+"\n") | |
count = 0; | |
bCount = 0; | |
while(count<=27150): | |
if(count<27150): | |
onPage = 30 | |
else: | |
onPage = 20 | |
testEl = WebDriverWait(driver, 20).until( | |
EC.visibility_of_element_located((By.XPATH,"//*[@id=\"scb-table-body\"]/tr[1]/td[3]")) | |
) | |
for i in range(onPage): | |
el = WebDriverWait(driver, 20).until( | |
EC.visibility_of_element_located((By.XPATH,"//*[@id=\"scb-table-body\"]/tr["+str(i+1)+"]/td[2]/img")) | |
) | |
con = el.get_attribute("src") | |
con = con.split("/")[-1] | |
if(con == "Bangladesh.png"): | |
bCount+=1 | |
rank = int(get_text(driver,driver.find_element_by_xpath("//*[@id=\"scb-table-body\"]/tr["+str(i+1)+"]/td[1]"))) | |
handle = get_text(driver,driver.find_element_by_xpath("//*[@id=\"scb-table-body\"]/tr["+str(i+1)+"]/td[3]")) | |
points = int(get_text(driver,driver.find_element_by_xpath("//*[@id=\"scb-table-body\"]/tr["+str(i+1)+"]/td[4]"))) | |
file.write(str(bCount).ljust(5)+str(rank).ljust(7)+handle.ljust(30)+str(points).ljust(6)+"\n") | |
print "Bangladeshi found: "+handle | |
count+=onPage | |
print "Processed handles: {}. Bangladeshi found: {}".format(count,bCount) | |
nxt = driver.find_element_by_link_text("Next »") | |
nxt.click() | |
WebDriverWait(driver, 20).until( | |
EC.staleness_of(testEl) | |
) | |
driver.close() | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment