diff --git a/database.db b/database.db new file mode 100644 index 0000000..ee1bb52 Binary files /dev/null and b/database.db differ diff --git a/main.py b/main.py index dbf5e54..deebbcc 100644 --- a/main.py +++ b/main.py @@ -2,18 +2,39 @@ import requests from bs4 import BeautifulSoup import re -headers = { - 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36' - } -response = requests.get( - 'https://online.top-academy.ru/education/ochno', - headers=headers +url = 'https://msk.top-academy.ru/blog' + +class BlogArticle: + ls = list() + def __init__(self,title,text): + self.title = title + self.text = text + BlogArticle.ls.append(self) + @classmethod + def count(cls): + return len(cls.ls) + + def to_dict(self): + return {'title': self.title, 'text':self.text} + +def scan(i): + headers = { + 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36' + } + response = requests.get( + url + (f'?page={i}' if i>1 else ''), + headers=headers ) -html = response.text -soup = BeautifulSoup(html,'html.parser') -result = soup.find_all("a", class_='styles_container__Yf7Qk') -for el in result: - name = el.find("span") - name = re.search(r'([^<>]+)',str(name)) - if name: - print(name.group(1)) + html = response.text + soup = BeautifulSoup(html,'html.parser') + result = soup.find_all("div", class_='styles_cardBody__qP0jN') + for el in result: + par = el.find_all("p") + BlogArticle(par[0].text,par[1].text) + +if __name__ == '__main__': + for i in range(3): + scan(i) + print(BlogArticle.count()) + for i in range(5): + print(BlogArticle.ls[i].to_dict())