Upload 3 files
Browse files- README.md +5 -4
- app.py +67 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.12.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Blogcr111111
|
| 3 |
+
emoji: ๐ข
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.12.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: blogcr111111
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def convert_to_mobile_url(url):
|
| 6 |
+
"""
|
| 7 |
+
PC URL์ ๋ชจ๋ฐ์ผ URL๋ก ๋ณํ.
|
| 8 |
+
"""
|
| 9 |
+
if "m.blog.naver.com" not in url:
|
| 10 |
+
if "blog.naver.com" in url:
|
| 11 |
+
url_parts = url.split("/")
|
| 12 |
+
if len(url_parts) >= 5:
|
| 13 |
+
user_id = url_parts[3]
|
| 14 |
+
post_id = url_parts[4]
|
| 15 |
+
return f"https://m.blog.naver.com/{user_id}/{post_id}"
|
| 16 |
+
return url
|
| 17 |
+
|
| 18 |
+
def scrape_naver_blog(url):
|
| 19 |
+
"""
|
| 20 |
+
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ์ ์ ๋ชฉ๊ณผ ๋ด์ฉ(ํ
์คํธ๋ง) ์คํฌ๋ํ.
|
| 21 |
+
"""
|
| 22 |
+
try:
|
| 23 |
+
# ๋ชจ๋ฐ์ผ URL ๋ณํ
|
| 24 |
+
mobile_url = convert_to_mobile_url(url)
|
| 25 |
+
print(f"Converted Mobile URL: {mobile_url}")
|
| 26 |
+
|
| 27 |
+
response = requests.get(mobile_url)
|
| 28 |
+
response.raise_for_status()
|
| 29 |
+
|
| 30 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 31 |
+
|
| 32 |
+
# ์ ๋ชฉ ์คํฌ๋ํ
|
| 33 |
+
title_element = soup.find("div", class_="se-module se-module-text se-title-text")
|
| 34 |
+
title = title_element.get_text(strip=True) if title_element else "์ ๋ชฉ์ ์ฐพ์ ์ ์์"
|
| 35 |
+
|
| 36 |
+
# ๋ณธ๋ฌธ ๋ด์ฉ ์คํฌ๋ํ
|
| 37 |
+
content_elements = soup.find_all("div", class_="se-module se-module-text")
|
| 38 |
+
content = "\n".join(
|
| 39 |
+
elem.get_text(strip=True) for elem in content_elements
|
| 40 |
+
) if content_elements else "๋ด์ฉ์ ์ฐพ์ ์ ์์"
|
| 41 |
+
|
| 42 |
+
# ๋๋ฒ๊น
๋ฉ์์ง ์ถ๋ ฅ
|
| 43 |
+
print(f"Scraped Title: {title}")
|
| 44 |
+
print(f"Scraped Content: {content}")
|
| 45 |
+
|
| 46 |
+
# ๊ฒฐ๊ณผ ๋ฐํ
|
| 47 |
+
result = f"์ ๋ชฉ: {title}\n\n๋ด์ฉ: {content}"
|
| 48 |
+
return result
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print(f"Error: {e}")
|
| 52 |
+
return f"Error: {e}"
|
| 53 |
+
|
| 54 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
| 55 |
+
def run_scraper(url):
|
| 56 |
+
return scrape_naver_blog(url)
|
| 57 |
+
|
| 58 |
+
interface = gr.Interface(
|
| 59 |
+
fn=run_scraper,
|
| 60 |
+
inputs=gr.Textbox(label="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ URL"),
|
| 61 |
+
outputs=gr.Textbox(label="์คํฌ๋ํ ๊ฒฐ๊ณผ"),
|
| 62 |
+
title="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ ์คํฌ๋ํ",
|
| 63 |
+
description="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ์ ์ ๋ชฉ๊ณผ ๋ด์ฉ์ ์คํฌ๋ํํฉ๋๋ค."
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|
| 3 |
+
bs4
|