Fresh
This commit is contained in:
34
pyth/srpskainfo.py
Normal file
34
pyth/srpskainfo.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def getNews(url):
|
||||
response = requests.get(url)
|
||||
|
||||
if response.status_code == 200:
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
|
||||
articles = soup.find_all('article', class_='news__item')
|
||||
|
||||
for index, article in enumerate(articles, start=1):
|
||||
title = article.find('h2').text.strip()
|
||||
content = article.find('p').text.strip()
|
||||
category = article.find('span').text.strip()
|
||||
slink = article.find('a')
|
||||
if slink:
|
||||
slink = slink.get('href', '')
|
||||
else:
|
||||
slink = ''
|
||||
|
||||
|
||||
print(f"{index}. Title: {title}")
|
||||
print(f" Content: {content}")
|
||||
print(f" Category: {category}")
|
||||
print(f"Link: {slink}")
|
||||
print('****************************')
|
||||
else:
|
||||
print(f"Error. Status code: {response.status_code}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
pUrl = 'https://srpskainfo.com/sve-vijesti/'
|
||||
|
||||
getNews(pUrl)
|
||||
Reference in New Issue
Block a user