Created
November 29, 2017 07:07
-
-
Save NuarkNoir/9a9713130787e7088a3cfec18c65d518 to your computer and use it in GitHub Desktop.
ACMP Tasks parser
This file contains hidden or 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
from bs4 import BeautifulSoup as bs | |
import requests | |
import jsonpickle | |
class ACMP(object): | |
def __init__(self, task_array): | |
self.tasks = task_array | |
class Task(object): | |
def __init__(self, id, title, topic, solution, difficulty, solvability, accepted): | |
self.id = id | |
self.title = title | |
self.topic = topic | |
self.solution = solution | |
self.difficulty = difficulty | |
self.solvability = solvability | |
self.accepted = accepted | |
def main(): | |
tasks_array = [] | |
for i in range(14): | |
print("Page", i) | |
url = "http://acmp.ru/index.asp?main=tasks&str=%20&page={}&id_type=0".format(i) | |
rq = requests.get(url) | |
doc = bs(rq.content, "html5lib") | |
rows = doc.select("tr.white") | |
for row in rows: | |
tds = row.find_all("td") | |
id = tds[0].text.strip() | |
title = tds[1].text.strip() | |
topic = tds[2].text.strip() | |
solution = tds[3].text.strip() | |
difficulty = tds[4].text.strip() | |
solvability = tds[5].text.strip() | |
accepted = tds[6].text.strip() | |
tasks_array.append(Task(id, title, topic, solution, difficulty, solvability, accepted)) | |
return(jsonpickle.encode(ACMP(tasks_array), unpicklable=False)) | |
with open("acmp_dump.json", "w+") as f: | |
f.write(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment