Spaces:
Sleeping
Sleeping
# app.py | |
import gradio as gr | |
import requests | |
from bs4 import BeautifulSoup | |
def scrape_naver_blog(url): | |
try: | |
# HTTP μμ² λ³΄λ΄κΈ° | |
response = requests.get(url) | |
response.raise_for_status() | |
# HTML νμ± | |
soup = BeautifulSoup(response.text, 'html.parser') | |
# μ λͺ© μ€ν¬λν | |
title_div = soup.find('div', class_='se-module se-module-text se-title-text') | |
if title_div: | |
title = title_div.get_text(strip=True) | |
else: | |
title = "μ λͺ©μ μ°Ύμ μ μμ΅λλ€." | |
# λ΄μ© μ€ν¬λν | |
content_div = soup.find('div', class_='se-module se-module-text se-quote') | |
if content_div: | |
content = "\n".join(p.get_text(strip=True) for p in content_div.find_all('p')) | |
else: | |
content = "λ΄μ©μ μ°Ύμ μ μμ΅λλ€." | |
return f"μ λͺ©:\n{title}\n\nλ΄μ©:\n{content}" | |
except requests.exceptions.RequestException as e: | |
return f"HTTP μμ² μλ¬: {e}" | |
except Exception as e: | |
return f"μ€ν¬λν μλ¬: {e}" | |
# Gradio μΈν°νμ΄μ€ μ μ | |
def main(): | |
gr.Interface( | |
fn=scrape_naver_blog, | |
inputs=gr.Textbox(label="λ€μ΄λ² λΈλ‘κ·Έ URL μ λ ₯"), | |
outputs=gr.Textbox(label="μ€ν¬λν κ²°κ³Ό"), | |
title="λ€μ΄λ² λΈλ‘κ·Έ μ€ν¬λνΌ", | |
description="λ€μ΄λ² λΈλ‘κ·Έμμ μ λͺ©κ³Ό λ΄μ©μ μ€ν¬λνν©λλ€. URLμ μ λ ₯νμΈμ." | |
).launch() | |
if __name__ == "__main__": | |
main() | |