Skip to content

Instantly share code, notes, and snippets.

@owenisas
Created April 14, 2021 14:10
Show Gist options
  • Save owenisas/a92e3ab6101e25bf00fe251dfd9bc9b4 to your computer and use it in GitHub Desktop.
Save owenisas/a92e3ab6101e25bf00fe251dfd9bc9b4 to your computer and use it in GitHub Desktop.
from selenium import webdriver
import time
import json
import requests
from selenium.webdriver.common.keys import Keys
code = 100
cookie_E = False
driver = webdriver.Chrome()
driver.get('https://judge.hkoi.org/')
with open('hkoicookies', 'r') as cookief:
cookieslist = json.load(cookief)
for cookie in cookieslist:
driver.add_cookie(cookie)
driver.refresh()
while True:
giturlc = 'https://raw.githubusercontent.com/hkoi/dse-exercises/master/exercises/D' + str(code) + '/solution.c'
giturlpas = 'https://raw.githubusercontent.com/hkoi/dse-exercises/master/exercises/D' + str(code) + '/solution.pas'
hkoiurl = 'https://judge.hkoi.org/task/D' + str(code) + '/submit'
driver.get(hkoiurl)
try:
respones = requests.get(url=giturlc).text
except:
respones = requests.get(url=giturlpas).text
driver.find_element_by_xpath('//*[@id="source-language"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="source-language"]/option[1]').click()
driver.find_element_by_xpath('//*[@id="source-editor"]/textarea').send_keys(respones)
driver.find_element_by_xpath('//*[@id="task-submit"]').click()
time.sleep(3)
else:
driver.find_element_by_xpath('//*[@id="source-language"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="source-language"]/option[2]').click()
driver.find_element_by_xpath('/html/body').click()
driver.find_element_by_xpath('//*[@id="source-editor"]/textarea').send_keys(respones)
time.sleep(5)
driver.find_element_by_xpath('//*[@id="source-editor"]/textarea').send_keys(Keys.CONTROL+'a')
driver.find_element_by_xpath('//*[@id="source-editor"]/textarea').clear()
time.sleep(5)
driver.find_element_by_xpath('//*[@id="source-editor"]/textarea').send_keys(respones)
time.sleep(3)
driver.find_element_by_xpath('//*[@id="task-submit"]').click()
time.sleep(3)
print(respones)
code = code + 1
print(code)
time.sleep(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment