Промежуточный результат парсинга расписания

This commit is contained in:
lulzette 2023-05-13 15:09:58 +03:00
parent a9f24607d4
commit 7711f0c589

75
main.py
View File

@ -1593,19 +1593,20 @@ if __name__ == '__main__':
post_data["&ctl00%24cphMain%24ctl06"] = -1 post_data["&ctl00%24cphMain%24ctl06"] = -1
post_data["&ctl00%24cphMain%24ctl07"] = -1 post_data["&ctl00%24cphMain%24ctl07"] = -1
post_data["&ctl00%24cphMain%24ctl08"] = -1 post_data["&ctl00%24cphMain%24ctl08"] = -1
print(post_data) # print(post_data)
post_headers = {"Content-Type": "application/x-www-form-urlencoded"} post_headers = {"Content-Type": "application/x-www-form-urlencoded"}
post_url = "https://guap.ru/rasp/?g=2" post_url = "https://guap.ru/rasp/?g=2"
# post_result = requests.post(post_url, data=post_data, headers=post_headers) # FIXME представляем в голове, что мы получили страницу
post_result = html_sample post_result = html_sample
# post_result = requests.post(post_url, data=post_data, headers=post_headers)
# Парсим полученные данные # Парсим полученные данные
soup_result = BeautifulSoup(post_result, 'html.parser') soup_result = BeautifulSoup(post_result, 'html.parser')
result_html = soup_result.find('div', {'class', 'result'}) # В переменную записываем само расписание, без остальной страницы
rasp_html = soup_result.find('div', {'class', 'result'})
# print(result_html.prettify()) # print(result_html.prettify())
@ -1613,7 +1614,7 @@ if __name__ == '__main__':
# Пример rasp_summary # Пример rasp_summary
# ( # (
# { # {
# "date": "понедельник", # "date": "Понедельник",
# "value": ( # "value": (
# { # {
# "time": "1 пара (9:3011:00)", # "time": "1 пара (9:3011:00)",
@ -1632,4 +1633,68 @@ if __name__ == '__main__':
# ) # )
# } # }
# ) # )
# Верстка сайта на высоте. Придется использовать next_siblings. Хвататься не за что.
# print(rasp_html.prettify())
rasp_html_inside = rasp_html.find('div')
# Это будет ужасно...
cur_day = ""
cur_lesson = ""
day_iterator = 0
for cur_sibl in rasp_html_inside.find_next_siblings():
tag_type = cur_sibl.name
# print(tag_type, cur_sibl.text)
match tag_type:
case 'h2':
# Header, пропускаем
print(cur_sibl.text)
case 'h3':
# День недели
# print(cur_sibl.text)
if cur_day == '' and cur_day != cur_sibl.text and day_iterator == 0:
cur_day = cur_sibl.text
elif cur_day != '' and cur_day != cur_sibl.text:
day_iterator += 1
cur_day = cur_sibl.text
case 'h4':
# какая пара
# print(cur_sibl.text)
cur_lesson = cur_sibl.text
case 'div':
# Что за пара, препод, место, аудитория
up_or_down = ""
get_b = cur_sibl.find('b')
# Верхняя/Нижняя пара
if get_b is None:
# Пара бывает всегда
pass
else:
if get_b.get('class') == 'up':
up_or_down = 'up'
else:
up_or_down = 'down'
# Что за пара
# Тип пары (лекция)
# Препод
# место, аудитория
# Итого, пишем в rasp_summary
print('sdfsdf ', day_iterator, cur_day, cur_lesson, up_or_down, cur_sibl.text)
# rasp_summary[cur_day][cur_lesson] = cur_sibl
# print(cur_sibl.text)
case _:
print('wtf')
print(rasp_summary)