Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f05f0a9f9 | |||
| 0bd384b252 |
BIN
Binary file not shown.
@@ -2,18 +2,44 @@ import requests
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import re
|
import re
|
||||||
|
|
||||||
headers = {
|
url = 'https://msk.top-academy.ru/blog'
|
||||||
'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'
|
|
||||||
}
|
class BlogArticle:
|
||||||
response = requests.get(
|
ls = list()
|
||||||
'https://online.top-academy.ru/education/ochno',
|
def __init__(self,title,text):
|
||||||
headers=headers
|
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
|
html = response.text
|
||||||
soup = BeautifulSoup(html,'html.parser')
|
soup = BeautifulSoup(html,'html.parser')
|
||||||
result = soup.find_all("a", class_='styles_container__Yf7Qk')
|
result = soup.find_all("div", class_='styles_cardBody__qP0jN')
|
||||||
for el in result:
|
for el in result:
|
||||||
name = el.find("span")
|
par = el.find_all("p")
|
||||||
name = re.search(r'<span>([^<>]+)</span>',str(name))
|
BlogArticle(par[0].text,par[1].text)
|
||||||
if name:
|
|
||||||
print(name.group(1))
|
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