Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import xlrd
- # Функция поиска ссылки на xls таблицы на сайте
- def findUrls():
- urls = []
- page = requests.get("https://www.mirea.ru/education/schedule-main/schedule/")
- soup = BeautifulSoup(page.text, "html.parser")
- result = soup.find("div", id = "toggle-3").findAll("a", {"class": "xls"})
- for item in result:
- urls.append(item.attrs["href"])
- return urls
- # Функция создания словаря, где ключ - группа, значение - предметы
- def createDictOfSubjs(cs):
- urls = findUrls()
- course1 = requests.get(urls[cs])
- book = xlrd.open_workbook(file_contents = course1.content)
- sheet = book.sheet_by_index(0)
- groupsSubjs = dict()
- oddSubjs = []
- evenSubjs = []
- for col_index in range(sheet.ncols):
- oddSubjs = []
- evenSubjs = []
- if (type(sheet.cell(1, col_index).value) == str and sheet.cell(1, col_index).value != "" ):
- if (sheet.cell(1,col_index).value[0] == "И"):
- for row_index in range(3,75):
- if (row_index % 2 == 0):
- evenSubjs.append([sheet.cell(row_index,col_index).value, sheet.cell(row_index,col_index+1).value, sheet.cell(row_index,col_index+2).value, sheet.cell(row_index,col_index+3).value])
- else:
- oddSubjs.append([sheet.cell(row_index,col_index).value, sheet.cell(row_index,col_index+1).value, sheet.cell(row_index,col_index+2).value, sheet.cell(row_index,col_index+3).value])
- groupsSubjs[sheet.cell(1,col_index).value] = []
- groupsSubjs[sheet.cell(1,col_index).value].append(evenSubjs)
- groupsSubjs[sheet.cell(1,col_index).value].append(oddSubjs)
- return groupsSubjs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement