Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
from bs4 import BeautifulSoup | |
import re | |
def fetch_pdf_links_and_titles(): | |
url = "https://finance.naver.com/research/company_list.naver" | |
response = requests.get(url) | |
soup = BeautifulSoup(response.text, 'html.parser') | |
seen_urls = set() | |
links_html = "" | |
# ๋ชจ๋ PDF ๋งํฌ์ ์ ๋ชฉ์ ์ฐพ์ต๋๋ค. | |
pdf_links = soup.find_all('a', href=re.compile("^https://ssl.pstatic.net/imgstock/upload/research/company/.*\.pdf$")) | |
for link in pdf_links: | |
title = link.text.strip() # ๋งํฌ ํ ์คํธ์์ ์ ๋ชฉ ์ถ์ถ | |
full_url = link['href'] | |
if full_url not in seen_urls: | |
seen_urls.add(full_url) | |
# HTML ๋ฌธ์์ด๋ก ๋งํฌ ์ถ๊ฐ | |
links_html += f"<div><a href='{full_url}' download='{full_url.split('/')[-1]}'>{title}</a></div>" | |
return links_html | |
# Gradio ์ธํฐํ์ด์ค | |
with gr.Blocks() as app: | |
btn_fetch = gr.Button("PDF ๋งํฌ ๋ฐ ์ ๋ณด ์กฐํ") | |
output_html = gr.HTML() | |
btn_fetch.click( | |
fn=fetch_pdf_links_and_titles, | |
outputs=output_html | |
) | |
app.launch() | |