File size: 993 Bytes
d9b1770
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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