Download app.py from SiteOn/amazonas2: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/spaces/SiteOn/amazonas2/resolve/main/app.py
- Command line
-
hf download hf://spaces/SiteOn/amazonas2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SiteOn/amazonas2/resolve/main/app.py
2.37 kB
| import requests | |
| import gradio as gr | |
| from bs4 import BeautifulSoup | |
| # Função para raspar as notícias do Portal do Holanda | |
| def scrape_news(): | |
| url = 'https://www.portaldoholanda.com.br' | |
| try: | |
| # Adicionando um timeout de 10 segundos | |
| response = requests.get('https://www.portaldoholanda.com.br/', timeout=10) | |
| except requests.Timeout: | |
| return "O pedido excedeu o tempo limite. Tente novamente mais tarde." | |
| except requests.RequestException as e: | |
| return f"Erro ao fazer a requisição: {e}" | |
| content = response.content | |
| site = BeautifulSoup(content, 'html.parser') | |
| noticias = site.findAll('div', attrs={'class': 'column homenoticia'}) | |
| resultados = ["<div style='font-size: 20px;'><strong>----------------Portal do Holanda - Últimas Notícias----------------</strong></div><br>"] | |
| for noticia in noticias: | |
| titulo = noticia.find('a') | |
| titulo_text = titulo.text.strip() if titulo else "Sem título" | |
| subtitulo = noticia.find('a', attrs={'class': 'destaque relacionada'}) | |
| subtitulo_text = subtitulo.text.strip() if subtitulo else "Sem subtítulo" | |
| link = url + titulo['href'] if titulo else "#" | |
| hora = noticia.find('p', attrs={'class': 'destaque ha'}) | |
| hora_text = hora.text.strip() if hora else "Sem horário de postagem" | |
| resultados.append( | |
| f"<div><strong>Título:</strong> {titulo_text if titulo else 'Não disponível'}</div>" | |
| f"<div><strong>Subtítulo:</strong> {subtitulo_text if subtitulo else 'Não disponível'}</div>" | |
| f"<div><strong>Link:</strong> <a href='{link}' target='_blank'>{link}</a></div>" | |
| f"<div><strong>Hora da Postagem:</strong> {hora_text if hora else 'Não disponível'}</div><br>" | |
| ) | |
| return "\n".join(resultados) | |
| iface_holanda = gr.Interface( | |
| fn=scrape_news, | |
| inputs=[], | |
| outputs="html", | |
| title="Portal do Holanda - Notícias", | |
| description="Fique por dentro das últimas notícias do Portal do Holanda!", | |
| css="footer.svelte-1rjryqp.svelte-1rjryqp.svelte-1rjryqp {display: none !important;} .panel.svelte-vt1mxs {background: #fff !important;} .show-api {display: none !important;} .svelte-mpyp5e a {display: none !important;} .textarea {font-size: 20px !important; }", | |
| allow_flagging= "never" | |
| ) | |
| iface_holanda.launch(share=True) | |