-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththenamibianfeed.py
34 lines (25 loc) · 1014 Bytes
/
thenamibianfeed.py
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
32
33
34
import requests
from bs4 import BeautifulSoup
# Define the base url of the website
base_url = "https://www.namibian.com.na"
# Define an empty list to store the news articles
news_list = []
# Make a request to the website and get the html content
response = requests.get(base_url)
html = response.text
# Parse the html content using BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
# Find all the div elements that have the class "news-item"
news_items = soup.find_all("div", class_="news-item")
# Loop through each news item
for news_item in news_items:
# Find the link, title and summary of the news article
link = base_url + news_item.find("a")["href"]
title = news_item.find("h2").text.strip()
summary = news_item.find("p").text.strip()
# Create a dictionary with the link, title and summary
news_dict = {"link": link, "title": title, "summary": summary}
# Append the dictionary to the news list
news_list.append(news_dict)
# Print the news list
print(news_list)