Skip to content

Instantly share code, notes, and snippets.

@raitonoberu
Last active March 25, 2024 06:34
Show Gist options
  • Save raitonoberu/53ec940dad2356330b9dd64c4d01d119 to your computer and use it in GitHub Desktop.
Save raitonoberu/53ec940dad2356330b9dd64c4d01d119 to your computer and use it in GitHub Desktop.
URL = "https://up.htmlacademy.ru/univer-web-dev-start/2/module/8/item/2/{}"
TASKS = range(1, 21)
COOKIES = {
"h2": "2b43bedb9vvh...0d97b35",
"cff2ec2f6032shfkrfkrfkr2102eab2a": "RU.f2373b52ss7bda976fvb966s31bcww2",
"48bedib3nbdga01fvsd2v1073248c986": "cohort20.ddv31aa6215...1bd8fe121c",
"phpdemo": "eyJ0eXAcmrmgV1...2owZT7qv4BBL5Zc",
}
# ----------
import re
import requests
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0",
"Origin": "https://up.htmlacademy.ru",
"Connection": "keep-alive",
"TE": "trailers",
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded",
# "Referer": ...
}
def get_params(url):
resp = requests.get(url, headers=headers, cookies=COOKIES)
assert resp.status_code == 200, f"couldn't get params, status code {resp.status_code}"
token = re.findall(r'meta name="csrf-token" content="([^"]*)"', resp.text)
assert len(token) != 0, "couldn't extract token"
task_id = re.findall(r'data-task-id="([^"]*)"', resp.text)
assert len(task_id) != 0, "couldn't extract task_id"
return token[0], task_id[0]
def solve(url, token, task_id):
data = {
"token": token,
"task_id": task_id,
"completed": 1,
"is_answering_triggered": False,
}
resp = requests.post(url, headers=headers, data=data, cookies=COOKIES)
assert resp.status_code == 200, f"couldn't solve, status code {resp.status_code}"
for t in TASKS:
url = URL.format(t)
headers["Referer"] = url
print(f"task {t}...", end="", flush=True)
try:
token, task_id = get_params(url)
solve(url, token, task_id)
except Exception as e:
print(e)
else:
print("ok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment