seawolf2357 commited on
Commit
7e27e95
·
verified ·
1 Parent(s): cdbedd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -4,22 +4,23 @@ from bs4 import BeautifulSoup
4
  import re
5
 
6
  def fetch_pdf_links_and_titles():
7
- url = "https://finance.naver.com/research/company_list.naver"
8
- response = requests.get(url)
9
- soup = BeautifulSoup(response.text, 'html.parser')
10
-
11
- seen_urls = set()
12
- links_html = ""
13
- # 모든 PDF 링크와 제목을 찾습니다.
14
- pdf_links = soup.find_all('a', href=re.compile("^https://ssl.pstatic.net/imgstock/upload/research/company/.*\.pdf$"))
15
- for link in pdf_links:
16
- title = link.text.strip() # 링크 텍스트에서 제목 추출
17
- full_url = link['href']
18
- if full_url not in seen_urls:
19
- seen_urls.add(full_url)
20
- # HTML 문자열로 링크 추가
21
- links_html += f"<div><a href='{full_url}' download='{full_url.split('/')[-1]}'>{title}</a></div>"
22
- return links_html
 
23
 
24
  # Gradio 인터페이스
25
  with gr.Blocks() as app:
 
4
  import re
5
 
6
  def fetch_pdf_links_and_titles():
7
+ try:
8
+ url = "https://finance.naver.com/research/company_list.naver"
9
+ response = requests.get(url)
10
+ soup = BeautifulSoup(response.text, 'html.parser')
11
+
12
+ seen_urls = set()
13
+ links_html = ""
14
+ pdf_links = soup.find_all('a', href=re.compile("^https://ssl.pstatic.net/imgstock/upload/research/company/.*\.pdf$"))
15
+ for link in pdf_links:
16
+ title = link.text.strip()
17
+ full_url = link['href']
18
+ if full_url not in seen_urls:
19
+ seen_urls.add(full_url)
20
+ links_html += f"<div><a href='{full_url}' download='{full_url.split('/')[-1]}'>{title}</a></div>"
21
+ return links_html if links_html else "No links found."
22
+ except Exception as e:
23
+ return f"An error occurred: {str(e)}"
24
 
25
  # Gradio 인터페이스
26
  with gr.Blocks() as app: