33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from DrissionPage.errors import ElementNotFoundError
|
|
|
|
from database.tinformationsource.model import TInformationSource
|
|
from database.tnews.model import TNews
|
|
from log.log_manager import logger
|
|
from seek.seek_base import SeekBase
|
|
from utils.time_utils import process_time
|
|
|
|
|
|
class Base(SeekBase):
|
|
def __init__(self, information_source: TInformationSource):
|
|
super().__init__(information_source)
|
|
|
|
def get_news(self):
|
|
news_result = []
|
|
_news_list = self.session.s_ele('.index_cards__AdZtA').s_eles('.ant-col ant-col-6')
|
|
|
|
for _news in _news_list:
|
|
tnews = TNews()
|
|
try:
|
|
tnews.title = _news.s_ele('tag:a').text
|
|
tnews.url = _news.s_ele('tag:a').link
|
|
_time = _news.s_ele('.small_text__dR01h').s_eles('tag:span')[1].text
|
|
tnews.occurrence_date = process_time(_time)
|
|
tnews.source = self.information_source.title
|
|
news_result.append(tnews)
|
|
except ElementNotFoundError as e:
|
|
logger.error(f"ElementNotFoundError {tnews.title}: {e} - Failed to find element in news item.")
|
|
except Exception as e:
|
|
logger.error(f'Unexpected error occurred: {e}')
|
|
|
|
return news_result
|