Update app.py
Browse files
app.py
CHANGED
|
@@ -23,13 +23,13 @@ def scrape_naver_blog(url):
|
|
| 23 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 24 |
|
| 25 |
# ์ ๋ชฉ ์ถ์ถ
|
| 26 |
-
#
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
if not title_element:
|
| 34 |
print("์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 35 |
title = "์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
|
@@ -38,10 +38,14 @@ def scrape_naver_blog(url):
|
|
| 38 |
print(f"์ถ์ถ๋ ์ ๋ชฉ: {title}")
|
| 39 |
|
| 40 |
# ๋ด์ฉ ํ
์คํธ ์ถ์ถ
|
| 41 |
-
#
|
| 42 |
-
#
|
| 43 |
-
content_elements = soup.find_all('span',
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
if not content_elements:
|
| 46 |
print("๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 47 |
content = "๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
|
@@ -60,16 +64,18 @@ def scrape_naver_blog(url):
|
|
| 60 |
return f"An error occurred: {e}"
|
| 61 |
|
| 62 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
)
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
| 75 |
iface.launch()
|
|
|
|
| 23 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 24 |
|
| 25 |
# ์ ๋ชฉ ์ถ์ถ
|
| 26 |
+
# ๋ค์ด๋ฒ ๋ธ๋ก๊ทธ์ ์ ๋ชฉ์ ์ผ๋ฐ์ ์ผ๋ก <h3> ํ๊ทธ ๋๋ ํน์ ํด๋์ค๋ช
์ ๊ฐ์ง๋๋ค.
|
| 27 |
+
# ์ค์ HTML ๊ตฌ์กฐ์ ๋ง๊ฒ ์์ ํด์ผ ํฉ๋๋ค.
|
| 28 |
+
title_element = soup.find('h3', {'class': 'se_textarea'}) # ์์ ํด๋์ค๋ช
|
| 29 |
+
if not title_element:
|
| 30 |
+
# ๋ค๋ฅธ ๊ฐ๋ฅํ ์์น ์๋
|
| 31 |
+
title_element = soup.find('span', {'class': 'se-fs- se-ff-'})
|
| 32 |
+
|
| 33 |
if not title_element:
|
| 34 |
print("์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 35 |
title = "์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
|
|
|
| 38 |
print(f"์ถ์ถ๋ ์ ๋ชฉ: {title}")
|
| 39 |
|
| 40 |
# ๋ด์ฉ ํ
์คํธ ์ถ์ถ
|
| 41 |
+
# ๋ค์ด๋ฒ ๋ธ๋ก๊ทธ์ ๋ด์ฉ์ ์ผ๋ฐ์ ์ผ๋ก <div> ํ๊ทธ ๋ด์ ํน์ ํด๋์ค๋ช
์ ๊ฐ์ง๋๋ค.
|
| 42 |
+
# ์ค์ HTML ๊ตฌ์กฐ์ ๋ง๊ฒ ์์ ํด์ผ ํฉ๋๋ค.
|
| 43 |
+
content_elements = soup.find_all('span', {'class': 'se-fs- se-ff-'}) # ์์ ํด๋์ค๋ช
|
| 44 |
|
| 45 |
+
if not content_elements:
|
| 46 |
+
# ๋ค๋ฅธ ๊ฐ๋ฅํ ์์น ์๋
|
| 47 |
+
content_elements = soup.find_all('div', {'class': 'se-component se-text se-l-default'})
|
| 48 |
+
|
| 49 |
if not content_elements:
|
| 50 |
print("๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 51 |
content = "๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
|
|
|
| 64 |
return f"An error occurred: {e}"
|
| 65 |
|
| 66 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
| 67 |
+
with gr.Blocks() as iface:
|
| 68 |
+
gr.Markdown("# ๋ค์ด๋ฒ ๋ธ๋ก๊ทธ ์คํฌ๋ํผ")
|
| 69 |
+
gr.Markdown("๋ค์ด๋ฒ ๋ธ๋ก๊ทธ URL์ ์
๋ ฅํ๋ฉด ์ ๋ชฉ๊ณผ ๋ด์ฉ์ ์ถ์ถํฉ๋๋ค.")
|
| 70 |
+
|
| 71 |
+
with gr.Row():
|
| 72 |
+
url_input = gr.Textbox(label="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ URL", placeholder="https://blog.naver.com/lafleur7/223723723486")
|
| 73 |
+
|
| 74 |
+
scrape_button = gr.Button("์คํฌ๋ํ")
|
| 75 |
+
|
| 76 |
+
output_text = gr.Textbox(label="๊ฒฐ๊ณผ", lines=20)
|
| 77 |
+
|
| 78 |
+
scrape_button.click(fn=scrape_naver_blog, inputs=url_input, outputs=output_text)
|
| 79 |
|
| 80 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
| 81 |
iface.launch()
|