Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f05f0a9f9 | |||
| 0bd384b252 | |||
| b7d3c30c86 |
BIN
Binary file not shown.
@@ -0,0 +1,45 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
|
||||
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}
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls,d):
|
||||
BlogArticle(d['title'],d['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("div", class_='styles_cardBody__qP0jN')
|
||||
for el in result:
|
||||
par = el.find_all("p")
|
||||
BlogArticle(par[0].text,par[1].text)
|
||||
|
||||
if __name__ == '__main__':
|
||||
BlogArticle.from_dict({'title':'Заголовок','text':'Текст статьи'})
|
||||
#for i in range(3):
|
||||
#scan(i)
|
||||
print(BlogArticle.count())
|
||||
for i in range(1):
|
||||
print(BlogArticle.ls[i].to_dict())
|
||||
Reference in New Issue
Block a user