Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import re
- file = open("all_themes2.txt", "w", encoding='utf-8')
- text = requests.get("http://hecs.info/").text
- file.write(text)
- all_pages = re.findall(r'<a href="theme/(.*?)">\s*?<div class=" hexagon hex_link (.*?)">', text)
- url = "http://hecs.info/theme/{}"
- all_themes = {}
- for subtheme in all_pages:
- if subtheme[0] == "581": continue
- try:
- text = requests.get(url.format(subtheme[0])).text
- except:
- # print("ERROR", subtheme)
- continue
- name = re.findall(r'<title>(.*?)</title>', text)
- template = r'<span class="target .*?">(.*&?)</span> <a target="_blank" href="(.*?)"'
- material = list(set(re.findall(template, text)))
- # print(material)
- task = []
- for val in material:
- if val[0].lower() == "informatics":
- task = val
- break
- description = "nil"
- # description = requests.get('https://ru.wikipedia.org/w/api.php?action=opensearch&search={}&prop=info&format=xml&inprop=url'.format(name.lower())).text
- if task: material.remove(task)
- if subtheme[1] in all_themes:
- all_themes[subtheme[1]] += ['Subtheme(\n name: "{}",\n description: "{}",\n material: {},\n tasks: {}),\n'.format(name[0], description, material, task)]
- else:
- all_themes[subtheme[1]] = ['Subtheme(\n name: "{}",\n description: "{}",\n material: {},\n tasks: {}),\n'.format(name[0], description, material, task)]
- for i in all_themes:
- if i == "hex_rec0":
- nameTheme = "Рекурсия"
- elif i == "hex_graph0":
- nameTheme = "Графы"
- elif i == "hex_search0":
- nameTheme = "Поиск"
- elif i == "hex_sort0":
- nameTheme = "Сортировки"
- elif i == "hex_dp0":
- nameTheme = "Динамическое программирование"
- elif i == "hex_geom0":
- nameTheme = "Геометрия"
- elif i == "hex_comb0":
- nameTheme = "Комбинаторика"
- elif i == "hex_data0":
- nameTheme = "Структуры данных"
- elif i == "hex_str0":
- nameTheme = "Строки"
- elif i == "hex_nums0":
- nameTheme = "Числа"
- elif i == "hex_eq0":
- nameTheme = "Уравнения"
- elif i == "hew_start":
- continue
- else:
- nameTheme = "Прочее"
- print("ErrorErrorError")
- file.write('Theme(name: "{}", subt: [\n'.format(nameTheme))
- for elem in all_themes[i]:
- file.write(elem)
- file.write(']),\n')
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement