Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import re
- import datetime
- import dateutil.parser as dparser
- class analyssaita:
- def __init__(self):
- self.page = requests.get('https://www.pkmpei.ru/')
- self.soup = BeautifulSoup(self.page.text, 'html.parser')
- def timetable(self):
- timetable1 = []
- timetable2 = []
- timetable3 = []
- timetable4 = []
- self.timetable = dict()
- s = ''
- l = 0
- timetable = str(self.soup.find(class_='title2'))
- timetable = re.split('; ', timetable)
- for i in timetable:
- if 'left' in i or 'center' in i:
- timetable1.append(i)
- for i in timetable1:
- if '<b>' in i:
- timetable2.append(i)
- timetable2 = re.split(';', str(timetable2))
- for i in timetable2:
- if '"><b>' in i:
- start = '"><b>'
- end = '</b></td>\\n<td style="text-align: center'
- i = i[i.find(start)+len(start):i.rfind(end)]
- timetable3.append(i)
- for i in timetable2:
- if '\\xa0' in i:
- if 'Выходной' in i:
- i = 'Выходной'
- else:
- i = re.findall('\d+', i)
- for j in range(len(i) - 2):
- if i[j] == '0':
- del i[j]
- elif i[j] == '010':
- i[j] = '10'
- elif i[-1] == '0':
- del i[-1]
- i = ''.join(map(str, i))
- timetable4.append(i)
- for i in range(len(timetable4)):
- if timetable4[i] == '010001700':
- timetable4[i] = '10:00 - 17:00'
- elif timetable4[i] == '10001700':
- timetable4[i] = '10:00 - 17:00'
- elif timetable4[i] == '10001600':
- timetable4[i] = '10:00 - 16:00'
- for i in range(len(timetable3)):
- self.timetable[l] = timetable3[i] + ': ' + timetable4[i]
- l = l +1
- print(self.timetable)
- def adress(self):
- adress = str(self.soup(class_="text"))
- start = 'Наш адрес'
- end = '/><br/><h1'
- adress = adress[adress.find(start)+len(start):adress.rfind(end)]
- start1 = '<div style="text-align: left;">'
- end1 = ', аудитория Б-209<br'
- adress1 = adress[adress.find(start1)+len(start1):adress.rfind(end1)]
- print(adress1)
- start2 = '<div style="text-align: left;">'
- end2 = '<br'
- self.adress2 = adress[adress.find(start2)+len(start2):adress.rfind(end2)]
- adress1 =adress1.replace(' ', '')
- self.adress1 = 'https://www.google.com/search?q=' + adress1
- print(self.adress1)
- def contactniedannie(self):
- contactniedannie = str(self.soup(class_="text"))
- start = 'Контактные данные'
- end = '</span><br/> </b></b>'
- start1 = '</h1> <br/> <b>'
- end1 = '<b><br/>'
- contactniedannie = contactniedannie[contactniedannie.find(start)+len(start):contactniedannie.rfind(end)] + 'JFKLDSJFLSD'
- self.telefon = contactniedannie[contactniedannie.find(start1)+len(start1):contactniedannie.rfind(end1)]
- print(self.telefon)
- start3 = '<span style="color: rgb(0, 0, 255);">'
- end3 = 'JFKLDSJFLSD'
- self.email = 'e-mail: ' + contactniedannie[contactniedannie.find(start3)+len(start3):contactniedannie.rfind(end3)]
- print(self.email)
- def novosti(self):
- novosti = str(self.soup.find_all(id="right_news_item"))
- novosti1 = []
- data = []
- data2 = []
- d = re.split(',', novosti)
- self.novosti = dict()
- urls = []
- news = []
- for i in d:
- if '<div id="right_news_item"' in i:
- novosti1.append(i)
- #print(novosti1)
- for i in range(len(novosti1)):
- start = 'href="'
- end ='">\n<div>'
- l = novosti1[i][novosti1[i].find(start)+len(start):novosti1[i].rfind(end)]
- url = 'https://www.pkmpei.ru/' + l
- urls.append(url)
- for i in urls:
- page = requests.get(i)
- soup = BeautifulSoup(page.text, 'html.parser')
- data1= str(soup.find(class_= 'title3'))
- start1 = '<div class="title3">'
- end1 = '</div>'
- data1 = data1[data1.find(start1)+len(start1):data1.rfind(end1)]
- data.append(data1)
- for i in data:
- if i not in data2:
- data2.append(i)
- text = str(soup.find_all(class_= 'text'))
- start2 ='<h1>'
- end2 = '</h1>'
- text = text[text.find(start2)+len(start2):text.rfind(end2)]
- news.append(text)
- for i in range(len(news)):
- if '</h1>\n<br><h1>' in news[i]:
- news[i] = news[i][news[i].find('<h1>'):]
- news[i] = news[i][4:]
- for i in range(len(data2)):
- self.novosti[data2[i]] = 'НОВОСТИ:' + '\n' + data2[i] + '\n' + news[i] + '\n' + 'Ссылка: ' + urls[i]
- print(self.novosti)
- t = analyssaita()
- print(t.timetable())
- print(t.adress())
- print(t.contactniedannie())
- print(t.novosti())
Advertisement
Add Comment
Please, Sign In to add comment