69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
|
||
def table_parser(soup, output):
|
||
#Date parser
|
||
date = (soup.find("main").findAll('span', style="color:black"))[1]
|
||
output["date"] = date.text.replace(u'\xa0', u'')
|
||
|
||
|
||
#Replaces parser
|
||
replaces = soup.findAll('tr')
|
||
for data in replaces:
|
||
|
||
text = (
|
||
data.find("td", valign="top")
|
||
.find("span", style="color:black")
|
||
.text.replace(u'\xa0', u'')
|
||
)
|
||
group = (
|
||
data.find("span", style="color:black")
|
||
.text.replace(" ", "").replace(u'\xa0', u''))
|
||
output["data"][group] = text
|
||
|
||
return output
|
||
|
||
def one_parser(soup, output):
|
||
raw_data = soup.find("main").findAll("p")
|
||
date = (
|
||
raw_data[3].find("span", style="font-size:16px;").b.text.lower()
|
||
.replace(u"\xa0", u"").replace("на", "").replace("\r", "")
|
||
.replace("ЗАМІНИ ДО РОЗКЛАДУ".lower(), "").split("\n")
|
||
)
|
||
output["date"] = date[1].lstrip(" ")
|
||
|
||
for p in raw_data[4].find("span",style="font-size:16px;").b.text.replace(u"\xa0", u"").split("\n"):
|
||
p = p.lstrip(" ")
|
||
data_rep = (p.lstrip(" ").split(" ", 1))
|
||
group = data_rep[0]
|
||
text = data_rep[1].replace("\r", "").lstrip(" ")
|
||
output["data"][group] = text
|
||
return output
|
||
|
||
def parser_two(soup, output):
|
||
raw_data = soup.find("main").findAll("p")[2]
|
||
data = raw_data.text.split("\n")
|
||
output["date"] = data[1].replace("\r", "")
|
||
|
||
for p in data[3:]:
|
||
r_data = p.split(maxsplit=1)
|
||
try:
|
||
group = r_data[0].replace(u"\xa0", u"").replace("\r", "")
|
||
text = r_data[1].replace(u"\xa0", u"").replace("\r", "")
|
||
except IndexError: break
|
||
output["data"][group] = text
|
||
return output
|
||
|
||
def parser3(soup, output):
|
||
raw_data = soup.find("main").findAll("p")
|
||
|
||
output["date"] = (
|
||
raw_data[2].text
|
||
.replace("\r", "")
|
||
.replace("ЗАМІНИ НА", "").lstrip(" ").rstrip(" ").lower()
|
||
)
|
||
for p in raw_data[5:]:
|
||
r_data = p.text.split("-", maxsplit=1)
|
||
group = r_data[0]
|
||
text = r_data[1]
|
||
output["data"][group] = text
|
||
return output
|