AIRider commited on
Commit
2b61a85
ยท
verified ยท
1 Parent(s): 5a7bb90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -2,15 +2,29 @@ import requests
2
  from bs4 import BeautifulSoup
3
  import gradio as gr
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def scrape_naver_blog(url):
6
  try:
7
  # Debugging: URL ํ™•์ธ
8
- print(f"Scraping URL: {url}")
9
 
10
- if not url.startswith("https://m.blog.naver.com"):
11
- raise ValueError("URL must be in the mobile format (https://m.blog.naver.com).")
 
12
 
13
- response = requests.get(url)
14
  response.raise_for_status()
15
 
16
  # Debugging: HTTP ์‘๋‹ต ์ƒํƒœ ํ™•์ธ
@@ -46,10 +60,10 @@ def run_scraper(url):
46
 
47
  interface = gr.Interface(
48
  fn=run_scraper,
49
- inputs=gr.Textbox(label="๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ URL (๋ชจ๋ฐ”์ผ ํ˜•์‹)"),
50
  outputs=gr.Textbox(label="์Šคํฌ๋ž˜ํ•‘ ๊ฒฐ๊ณผ"),
51
  title="๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ ์Šคํฌ๋ž˜ํ•‘",
52
- description="๋ชจ๋ฐ”์ผ URL์„ ์ž…๋ ฅํ•˜๋ฉด ๋ธ”๋กœ๊ทธ์˜ ์ œ๋ชฉ๊ณผ ํ…์ŠคํŠธ ๋‚ด์šฉ์„ ์Šคํฌ๋ž˜ํ•‘ํ•ฉ๋‹ˆ๋‹ค."
53
  )
54
 
55
  if __name__ == "__main__":
 
2
  from bs4 import BeautifulSoup
3
  import gradio as gr
4
 
5
+ def convert_to_mobile_url(url):
6
+ """
7
+ ์ž…๋ ฅ๋œ 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
  try:
20
  # Debugging: URL ํ™•์ธ
21
+ print(f"Original URL: {url}")
22
 
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
  # Debugging: HTTP ์‘๋‹ต ์ƒํƒœ ํ™•์ธ
 
60
 
61
  interface = gr.Interface(
62
  fn=run_scraper,
63
+ inputs=gr.Textbox(label="๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ URL"),
64
  outputs=gr.Textbox(label="์Šคํฌ๋ž˜ํ•‘ ๊ฒฐ๊ณผ"),
65
  title="๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ ์Šคํฌ๋ž˜ํ•‘",
66
+ description="๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ URL์„ ์ž…๋ ฅํ•˜๋ฉด ๋ชจ๋ฐ”์ผ URL๋กœ ๋ณ€ํ™˜ ํ›„ ์ œ๋ชฉ๊ณผ ํ…์ŠคํŠธ ๋‚ด์šฉ์„ ์Šคํฌ๋ž˜ํ•‘ํ•ฉ๋‹ˆ๋‹ค."
67
  )
68
 
69
  if __name__ == "__main__":