Итоговый проект

This commit is contained in:
2026-06-10 20:48:42 +03:00
parent b7d3c30c86
commit 0bd384b252
2 changed files with 35 additions and 14 deletions
+35 -14
View File
@@ -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'<span>([^<>]+)</span>',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())