Парсинг списка групп+заполнение формы для отправки POST запроса
This commit is contained in:
parent
202a6b1383
commit
a8580c67e5
44
main.py
44
main.py
@ -7,6 +7,7 @@
|
||||
# Забрать результат (готовое расписание)
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
|
||||
html_sample = """
|
||||
|
||||
@ -1484,6 +1485,8 @@ function __doPostBack(eventTarget, eventArgument) {
|
||||
|
||||
useragent = "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0"
|
||||
|
||||
stud_group = "1011"
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Hello, fucker")
|
||||
soup = BeautifulSoup(html_sample, 'html.parser')
|
||||
@ -1547,10 +1550,49 @@ if __name__ == '__main__':
|
||||
val = soup.find('input', {"id": i['name']})
|
||||
i['value'] = val.get('value')
|
||||
|
||||
print(cryptshits)
|
||||
# print(cryptshits)
|
||||
|
||||
# Теперь нам надо распарсить список групп и найти нужную
|
||||
|
||||
rasp = soup.find('div', {"class": "rasp"})
|
||||
|
||||
rasp_div_form = rasp.find('div', {"class": "form"})
|
||||
|
||||
groups = list()
|
||||
group_keyword = "группа:"
|
||||
|
||||
for i in rasp_div_form.find_all('span'):
|
||||
group_html_block = i.find(string=re.compile(group_keyword))
|
||||
if group_html_block is None:
|
||||
break
|
||||
else:
|
||||
for group in group_html_block.parent.findAll('option'):
|
||||
# print(group.contents, group.get('value'))
|
||||
if group.get('value') != "-1":
|
||||
groups.append({
|
||||
"name": group.contents,
|
||||
"html_value": group.get('value')
|
||||
})
|
||||
# print(group_html_block)
|
||||
# print(group_html_block.parent)
|
||||
|
||||
# print(groups)
|
||||
|
||||
# Формируем POST data
|
||||
|
||||
post_data = dict()
|
||||
# Заполняем дату криптохуйней
|
||||
for i in cryptshits:
|
||||
post_data[i['name']] = i['value']
|
||||
# Ищем группу
|
||||
for group in groups:
|
||||
if group['name'] == stud_group:
|
||||
post_data['ctl00%24cphMain%24ctl05=2'] = group['value']
|
||||
# Заполняем как есть, нам это не интересно
|
||||
post_data["&ctl00%24cphMain%24ctl06"] = -1
|
||||
post_data["&ctl00%24cphMain%24ctl07"] = -1
|
||||
post_data["&ctl00%24cphMain%24ctl08"] = -1
|
||||
print(post_data)
|
||||
|
||||
#
|
||||
# <form action="./?g=2" id="Form1" method="post">
|
||||
|
Loading…
Reference in New Issue
Block a user