51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
import datetime
|
|
|
|
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.content_base import ContentBase
|
|
|
|
|
|
class ThePaperContent(ContentBase):
|
|
def __init__(self, news: TNews):
|
|
super().__init__(news)
|
|
|
|
def get_content(self):
|
|
content_ = ''
|
|
try:
|
|
content_ = self.session.s_ele('.^index_cententWrap').text
|
|
except ElementNotFoundError as e:
|
|
try:
|
|
# 视频
|
|
content_ = self.session.s_ele('.^header_desc').text
|
|
except ElementNotFoundError as e:
|
|
content_ = 'not found element'
|
|
return content_
|
|
|
|
|
|
def get_content(information_source: TInformationSource) -> list:
|
|
the_paper_content = ThePaperContent(information_source)
|
|
content = the_paper_content.get_content()
|
|
the_paper_content.finish()
|
|
return content
|
|
|
|
|
|
def content_task(news: TNews):
|
|
logger.info(f'{news.title} news_task start execute at {datetime.datetime.now()}', )
|
|
ofweek_com_ai = ThePaperContent(news)
|
|
ofweek_com_ai.do_seek_task()
|
|
ofweek_com_ai.finish()
|
|
logger.info(f'{news.title} news_task end execute at {datetime.datetime.now()}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logger.info('This module is not for direct call!')
|
|
news_ = TNews()
|
|
news_.is_static = True
|
|
news_.url = 'https://www.thepaper.cn/newsDetail_forward_29745442'
|
|
content = get_content(news_)
|
|
logger.info(content)
|
|
logger.info('Done.')
|