-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (22 loc) · 1.06 KB
/
main.py
File metadata and controls
27 lines (22 loc) · 1.06 KB
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
from requests import get
from bs4 import BeautifulSoup
from rich import print
url = 'https://www.cbr.com/'
soup = BeautifulSoup(get(url).text, 'lxml')
# Get the featured articles
all_articles = soup.find('section', class_='w-featured-pinned-article').find_all('article')
# Loop through each article in the `all_articles` list and print the results
for article in all_articles:
title = article.find('a', class_='bc-title-link')
all_image_sources = article.find('picture').find_all('source')
# Print the title, link, and image sources
print(f'''
[bold green]Title[/bold green]: [blue]{title.text.strip()}[/blue]
[bold green]Link[/bold green]: [blue]https://www.cbr.com{title["href"]}[/blue]
[bold green]Image sources[/bold green]:''')
# Loop through each image source in the `all_image_sources` list and print the results
for image_source in all_image_sources:
print(f'''
[bold yellow]Link[/bold yellow]: [blue]{image_source["srcset"]}[/blue]
[bold yellow]Size[/bold yellow]: [red]{image_source["sizes"]}[/red]
''')