Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,42 +3,36 @@ import re
|
|
3 |
import requests
|
4 |
from bs4 import BeautifulSoup
|
5 |
|
6 |
-
def
|
7 |
-
# URL ์ ํจ์ฑ ๊ฒ์ฌ ์ถ๊ฐ
|
8 |
-
if not re.match(r'http[s]?://', url):
|
9 |
-
return ["Invalid URL"]
|
10 |
-
|
11 |
response = requests.get(url)
|
12 |
soup = BeautifulSoup(response.text, 'html.parser')
|
13 |
|
|
|
|
|
|
|
14 |
pdf_links = []
|
15 |
for link in soup.find_all('a', href=True):
|
16 |
if re.search(r'\.pdf', link['href']):
|
17 |
pdf_links.append(link['href'])
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
-
def
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
html = ""
|
27 |
for link in pdf_links:
|
28 |
html += f'<a href="{link}" target="_blank" download>{link}</a><br/>'
|
29 |
-
return html
|
30 |
|
31 |
-
|
32 |
-
pdf_links = extract_pdf_links(url)
|
33 |
-
if keyword: # ํค์๋๊ฐ ๋น์ด์์ง ์์ ๊ฒฝ์ฐ์๋ง ํํฐ๋ง
|
34 |
-
pdf_links = filter_links_by_keyword(pdf_links, keyword)
|
35 |
-
return generate_html(pdf_links)
|
36 |
|
37 |
-
title = "๋ค์ด๋ฒ ์ฆ๊ถ ๋ฆฌ์์น
|
38 |
|
39 |
-
iface = gr.Interface(
|
40 |
-
inputs=
|
41 |
-
outputs="text",
|
42 |
title=title)
|
43 |
|
44 |
iface.launch()
|
|
|
3 |
import requests
|
4 |
from bs4 import BeautifulSoup
|
5 |
|
6 |
+
def extract_pdf_links_and_title(url):
|
|
|
|
|
|
|
|
|
7 |
response = requests.get(url)
|
8 |
soup = BeautifulSoup(response.text, 'html.parser')
|
9 |
|
10 |
+
# ํ์ด์ง ์ ๋ชฉ ์ถ์ถ
|
11 |
+
page_title = soup.title.text if soup.title else "No title found"
|
12 |
+
|
13 |
pdf_links = []
|
14 |
for link in soup.find_all('a', href=True):
|
15 |
if re.search(r'\.pdf', link['href']):
|
16 |
pdf_links.append(link['href'])
|
17 |
|
18 |
+
# PDF ๋งํฌ์ ํ์ด์ง ์ ๋ชฉ์ ๋ฐํ
|
19 |
+
return pdf_links[:100], page_title
|
20 |
|
21 |
+
def generate_html(pdf_links_and_title):
|
22 |
+
pdf_links = pdf_links_and_title[0] # PDF ๋งํฌ ๋ฆฌ์คํธ
|
23 |
+
page_title = pdf_links_and_title[1] # ํ์ด์ง ์ ๋ชฉ
|
24 |
|
25 |
+
html = f"<h1>{page_title}</h1>" # ์ ๋ชฉ์ HTML์ ์ถ๊ฐ
|
|
|
26 |
for link in pdf_links:
|
27 |
html += f'<a href="{link}" target="_blank" download>{link}</a><br/>'
|
|
|
28 |
|
29 |
+
return html
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
title = "๋ค์ด๋ฒ ์ฆ๊ถ ๋ฆฌ์์น ๋งํฌ- https://finance.naver.com/research/company_list.naver"
|
32 |
|
33 |
+
iface = gr.Interface(fn=extract_pdf_links_and_title,
|
34 |
+
inputs="text",
|
35 |
+
outputs=["text", "html"],
|
36 |
title=title)
|
37 |
|
38 |
iface.launch()
|