diff --git a/app.py b/app.py
@@ -188,39 +188,26 @@ def shodan():
@app.route('/krcert')
def krcert():
- url = "https://www.krcert.or.kr/kr/bbs/list.do?menuNo=205020&bbsId=B0000133"
+ url = 'https://www.krcert.or.kr/kr/bbs/list.do?bbsId=B0000133&menuNo=205020'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
-
- table = soup.find('div', {'class': 'tbl'}).find('table')
- if table is None:
- return "Table not found on the page."
-
- rows = table.find_all('tr')[1:] # get all rows except the header row
+ table = soup.find('table')
+ rows = table.find_all('tr')
posts = []
+ now = datetime.now()
for row in rows:
cols = row.find_all('td')
- if len(cols) >= 5:
- title_tag = cols[1].find('a')
- date_tag = cols[4]
-
- # Check if title_tag or date_tag is None before calling get_text
- if title_tag is None or date_tag is None:
- continue
-
- title = title_tag.get_text(strip=True)
- date = date_tag.get_text(strip=True)
-
- post_date = datetime.strptime(date, "%Y-%m-%d")
-
- if (datetime.now() - post_date).total_seconds() <= 518400:
- posts.append((title, date))
-
- if not posts:
- return "No new posts in the last 48 hours."
+ if len(cols) > 0:
+ date_str = cols[4].text.strip()
+ post_date = datetime.strptime(date_str, "%Y-%m-%d")
+ if (now - post_date).days <= 2:
+ title = cols[1].text.strip()
+ link = "https://www.krcert.or.kr" + cols[1].find('a')['href']
+ posts.append({'title': title, 'date': date_str, 'link': link})
return render_template('krcert.html', posts=posts)
+
if __name__ == '__main__':
app.run()
diff --git a/templates/ascii_to_char.html b/templates/ascii_to_char.html
@@ -44,6 +44,9 @@
<li class="nav-item">
<a class="nav-link" href="/shodan">Shodan</a>
</li>
+ <li class="nav-item">
+ <a class="nav-link" href="/krcert">Krcert</a>
+ </li>
</ul>
</div>
</nav>
diff --git a/templates/index.html b/templates/index.html
@@ -41,6 +41,9 @@
<li class="nav-item">
<a class="nav-link" href="/shodan">Shodan</a>
</li>
+ <li class="nav-item">
+ <a class="nav-link" href="/krcert">Krcert</a>
+ </li>
</ul>
</div>
</nav>
diff --git a/templates/krcert.html b/templates/krcert.html
@@ -1,6 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
+ <style>
+ table {
+ width: 100%;
+ border-collapse: collapse;
+ }
+ th,
+ td {
+ padding: 8px;
+ text-align: left;
+ border-bottom: 1px solid #ddd;
+ }
+ tr:hover {
+ background-color: #f5f5f5;
+ }
+ </style>
<meta charset="UTF-8" />
<title>KRCERT</title>
<!-- Bootstrap CSS -->
@@ -45,23 +60,25 @@
</nav>
<div class="container">
- <h1 class="mt-5">KRCERT Posts</h1>
- <table class="table mt-4">
- <thead>
- <tr>
- <th>Title</th>
- <th>Date</th>
- </tr>
- </thead>
- <tbody>
- {% for result in results %}
- <tr>
- <td>{{ result.title }}</td>
- <td>{{ result.date }}</td>
- </tr>
- {% endfor %}
- </tbody>
+ <h1>KRCERT 보안공지 알림</h1>
+ {% if posts %}
+ <table>
+ <tr>
+ <th>No.</th>
+ <th>Title</th>
+ <th>Date</th>
+ </tr>
+ {% for post in posts %}
+ <tr>
+ <td>{{ loop.index }}</td>
+ <td><a href="{{ post['link'] }}">{{ post['title'] }}</a></td>
+ <td>{{ post['date'] }}</td>
+ </tr>
+ {% endfor %}
</table>
+ {% else %}
+ <p>2일 이내에 업데이트된 글이 없습니다.</p>
+ {% endif %}
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"></script>
diff --git a/templates/news.html b/templates/news.html
@@ -41,6 +41,9 @@
<li class="nav-item">
<a class="nav-link" href="/shodan">Shodan</a>
</li>
+ <li class="nav-item">
+ <a class="nav-link" href="/krcert">Krcert</a>
+ </li>
</ul>
</div>
</nav>
diff --git a/templates/shodan.html b/templates/shodan.html
@@ -41,6 +41,9 @@
<li class="nav-item">
<a class="nav-link" href="/shodan">Shodan</a>
</li>
+ <li class="nav-item">
+ <a class="nav-link" href="/krcert">Krcert</a>
+ </li>
</ul>
</div>
</nav>
diff --git a/templates/shodan_domain.html b/templates/shodan_domain.html
@@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="/shodan">Shodan</a>
</li>
+ <li class="nav-item">
+ <a class="nav-link" href="/krcert">Krcert</a>
+ </li>
</ul>
</div>
</nav>
diff --git a/templates/utf8_decoder.html b/templates/utf8_decoder.html
@@ -41,6 +41,9 @@
<li class="nav-item">
<a class="nav-link" href="/shodan">Shodan</a>
</li>
+ <li class="nav-item">
+ <a class="nav-link" href="/krcert">Krcert</a>
+ </li>
</ul>
</div>
</nav>
|