-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
31 lines (23 loc) · 840 Bytes
/
parser.py
File metadata and controls
31 lines (23 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from bs4 import BeautifulSoup
import urllib.request
req = urllib.request.urlopen('https://www.ua-football.com/sport')
html = req.read()
soup = BeautifulSoup(html, 'html.parser')
news = soup.find_all('li', class_='liga-news-item')
results = []
for item in news:
title = item.find('span', class_='d-block').get_text(strip=True)
desc = item.find('span', class_='name-dop').get_text(strip=True)
href = item.a.get('href')
results.append({
'title': title,
'desc': desc,
'href': href,
})
print(results)
f = open('news.txt', 'w', encoding='utf-8')
i = 1
for item in results:
f.write(f'Новость №{i}\n\nНазвание: {item["title"]}\nОписание: {item["desc"]}\nСсылка: {item["href"]}\n\n************************\n')
i += 1
f.close()