From e6348b0c5236bd8364991501f1e988f6f4defd0d Mon Sep 17 00:00:00 2001 From: Meghdad Date: Mon, 18 Nov 2024 13:13:26 +0330 Subject: [PATCH] change schedule add block needle --- main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 1af8828..c803d1c 100644 --- a/main.py +++ b/main.py @@ -32,15 +32,15 @@ def make_message(html: str) -> str: soup = BeautifulSoup(html, 'html.parser') # table = soup.find('table', id='ctl01_ctl00_myDataList') - block_needle = 'بلوك A2' - paragraphs = soup.find_all('p') - block = soup.find('p', string=lambda text: isinstance(text, str) and block_needle in text) - if not block: + block_needle = 'بلوک A2' + try: + paragraphs = soup.find_all('p') + block = soup.find('p', string=lambda text: isinstance(text, str) and block_needle in text) + time_index = paragraphs.index(block) - 1 + return paragraphs[time_index].get_text(separator='\n', strip=True) + except: return f"اطلاعات {block_needle} یافت نشد!" - time_index = paragraphs.index(block) - 1 - return paragraphs[time_index].get_text(separator='\n', strip=True) - def main() -> None: try: