Update app.py
Browse files
app.py
CHANGED
|
@@ -23,36 +23,44 @@ def scrape_naver_blog(url):
|
|
| 23 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 24 |
|
| 25 |
# ์ ๋ชฉ ์ถ์ถ
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
print("์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 35 |
title = "์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 36 |
-
else:
|
| 37 |
-
title = title_element.get_text(strip=True)
|
| 38 |
-
print(f"์ถ์ถ๋ ์ ๋ชฉ: {title}")
|
| 39 |
|
| 40 |
# ๋ด์ฉ ํ
์คํธ ์ถ์ถ
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
content_elements = soup.find_all('span', {'class': 'se-fs- se-ff-'}) # ์์ ํด๋์ค๋ช
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
print("๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 51 |
-
content = "๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 52 |
else:
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# ์ถ๋ ฅ ํ์ ์ง์
|
| 58 |
output = f"์ ๋ชฉ: {title}\n\n๋ด์ฉ: {content}"
|
|
|
|
| 23 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 24 |
|
| 25 |
# ์ ๋ชฉ ์ถ์ถ
|
| 26 |
+
# ์ค์ HTML ๊ตฌ์กฐ์ ๋ง๊ฒ ํด๋์ค๋ช
๊ณผ ํ๊ทธ๋ฅผ ์์ ํด์ผ ํฉ๋๋ค.
|
| 27 |
+
title = None
|
| 28 |
+
|
| 29 |
+
# ์์ 1: <h3 class="se_textarea">์ ์ ๋ชฉ์ด ์๋ ๊ฒฝ์ฐ
|
| 30 |
+
title_element = soup.find('h3', class_='se_textarea')
|
| 31 |
+
if title_element and title_element.get_text(strip=True):
|
| 32 |
+
title = title_element.get_text(strip=True)
|
| 33 |
+
print(f"์ถ์ถ๋ ์ ๋ชฉ (h3.se_textarea): {title}")
|
| 34 |
|
| 35 |
+
# ์์ 2: meta ํ๊ทธ์์ ์ ๋ชฉ ์ถ์ถ
|
| 36 |
+
if not title:
|
| 37 |
+
title_meta = soup.find('meta', property='og:title')
|
| 38 |
+
if title_meta and title_meta.get('content'):
|
| 39 |
+
title = title_meta.get('content').strip()
|
| 40 |
+
print(f"์ถ์ถ๋ ์ ๋ชฉ (meta og:title): {title}")
|
| 41 |
+
|
| 42 |
+
if not title:
|
| 43 |
print("์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 44 |
title = "์ ๋ชฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# ๋ด์ฉ ํ
์คํธ ์ถ์ถ
|
| 47 |
+
# ์ค์ HTML ๊ตฌ์กฐ์ ๋ง๊ฒ ํด๋์ค๋ช
๊ณผ ํ๊ทธ๋ฅผ ์์ ํด์ผ ํฉ๋๋ค.
|
| 48 |
+
content = None
|
|
|
|
| 49 |
|
| 50 |
+
# ์์ 1: <div class="se-main-container"> ๋ด์ ๋ชจ๋ ํ
์คํธ ์ถ์ถ
|
| 51 |
+
content_container = soup.find('div', class_='se-main-container')
|
| 52 |
+
if content_container:
|
| 53 |
+
content = content_container.get_text(separator='\n', strip=True)
|
| 54 |
+
print(f"์ถ์ถ๋ ๋ด์ฉ (div.se-main-container): {content[:100]}...") # ์ผ๋ถ๋ง ์ถ๋ ฅ
|
|
|
|
|
|
|
| 55 |
else:
|
| 56 |
+
# ์์ 2: ๋ชจ๋ <p> ํ๊ทธ๋ฅผ ํฉ์น๋ ๋ฐฉ๋ฒ
|
| 57 |
+
p_tags = soup.find_all('p')
|
| 58 |
+
if p_tags:
|
| 59 |
+
content = '\n'.join([p.get_text(strip=True) for p in p_tags])
|
| 60 |
+
print(f"์ถ์ถ๋ ๋ด์ฉ (p tags): {content[:100]}...")
|
| 61 |
+
else:
|
| 62 |
+
print("๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค.")
|
| 63 |
+
content = "๋ด์ฉ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
| 64 |
|
| 65 |
# ์ถ๋ ฅ ํ์ ์ง์
|
| 66 |
output = f"์ ๋ชฉ: {title}\n\n๋ด์ฉ: {content}"
|