Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,11 +20,24 @@ def generate_naver_search_url(query):
|
|
20 |
url = base_url + "&".join(f"{key}={value}" for key, value in params.items())
|
21 |
return url
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
with gr.Interface(
|
24 |
-
fn=generate_naver_search_url,
|
25 |
inputs=gr.Textbox(label="ํค์๋๋ฅผ ์
๋ ฅํ์ธ์"),
|
26 |
-
outputs=gr.Textbox(label="
|
27 |
-
title="๋ค์ด๋ฒ ๊ฒ์
|
28 |
-
description="๊ฒ์ ์ฟผ๋ฆฌ๋ฅผ ์
๋ ฅํ์ฌ ๋ค์ด๋ฒ ๊ฒ์
|
29 |
) as demo:
|
30 |
demo.launch()
|
|
|
20 |
url = base_url + "&".join(f"{key}={value}" for key, value in params.items())
|
21 |
return url
|
22 |
|
23 |
+
def crawl_naver_search_results(url):
|
24 |
+
response = requests.get(url)
|
25 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
26 |
+
results = []
|
27 |
+
for li in soup.find_all("li", class_="bx"):
|
28 |
+
for div in li.find_all("div", class_="detail_box"):
|
29 |
+
for div2 in div.find_all("div", class_="title_area"):
|
30 |
+
title = div2.text.strip()
|
31 |
+
for a in div2.find_all("a", href=True):
|
32 |
+
link = a["href"]
|
33 |
+
results.append(f"{title}: {link}")
|
34 |
+
return "\n".join(results)
|
35 |
+
|
36 |
with gr.Interface(
|
37 |
+
fn=lambda query: crawl_naver_search_results(generate_naver_search_url(query)),
|
38 |
inputs=gr.Textbox(label="ํค์๋๋ฅผ ์
๋ ฅํ์ธ์"),
|
39 |
+
outputs=gr.Textbox(label="ํฌ๋กค๋ง๋ ์ ๋ชฉ๊ณผ ๋งํฌ ๋ชฉ๋ก"),
|
40 |
+
title="๋ค์ด๋ฒ ๊ฒ์ ์ ๋ชฉ๊ณผ ๋งํฌ ํฌ๋กค๋ฌ",
|
41 |
+
description="๊ฒ์ ์ฟผ๋ฆฌ๋ฅผ ์
๋ ฅํ์ฌ ๋ค์ด๋ฒ ๊ฒ์ ๊ฒฐ๊ณผ์์ ์ ๋ชฉ๊ณผ ๋งํฌ๋ฅผ ํฌ๋กค๋งํฉ๋๋ค"
|
42 |
) as demo:
|
43 |
demo.launch()
|