import requests from bs4 import BeautifulSoup from crewai_tools import BaseTool class GetCryptoNews(BaseTool): name: str = "GetCryptoNews" description: str = "fetch news from https://cryptonews.com/" def _run(self, argument: str) -> str: url = "https://cryptonews.com/" response = requests.get(url) webpage = response.text soup = BeautifulSoup(webpage,'html.parser') articles = soup.select("#main-news-left .title-news-slider") data = "" for article in articles[:5]: title = article.text.strip() url = article['href'] response = requests.get(url) article_page = response.text soup = BeautifulSoup(article_page, 'html.parser') data += f'Title: {title}, Content: ' for section in soup.find_all(['h1', 'h2', 'h3', 'p']): data += section.text.strip() return data