diff --git a/Scripts/techStream/techStream.py b/Scripts/techStream/techStream.py index 727448a..e4bd586 100644 --- a/Scripts/techStream/techStream.py +++ b/Scripts/techStream/techStream.py @@ -11,19 +11,29 @@ # Loop through each URL and scrape the latest articles for url in urls: - response = requests.get(url) - soup = BeautifulSoup(response.content, features="xml") - - # Extract the title, link, and summary of the latest articles - articles = soup.find_all("item")[:5] - for article in articles: - title = article.find("title").text - link = article.find("link").text - summary = article.find("description").text - - # Add the title, link, and summary to the HTML document - html += "
" + summary + "
" + try: + response = requests.get(url) + response.raise_for_status() #check for successful request + soup = BeautifulSoup(response.content, features="xml") + # Extract the title, link, and summary of the latest articles + articles = soup.find_all("item")[:5] #latest 5 articles + for article in articles: + title = article.find("title").text + link = article.find("link").text + summary = article.find("description").text + + # extracting publivcation date(if there) + pub_date=article.find("pubDate") + pub_date = pub_date.text if pub_date else "No Date Available" + + # Add the title, link, summary and publication date to the HTML document + html += f"Published on: {pub_date}
" + html += f"{summary}
" + except requests.exceptions.RequestException as e: + print(f"Error fetching {url}: {e}") + + # Close the HTML document html += "