import peter
This commit is contained in:
0
seek/mittr_com/__init__.py
Normal file
0
seek/mittr_com/__init__.py
Normal file
BIN
seek/mittr_com/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
seek/mittr_com/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
seek/mittr_com/__pycache__/content.cpython-312.pyc
Normal file
BIN
seek/mittr_com/__pycache__/content.cpython-312.pyc
Normal file
Binary file not shown.
BIN
seek/mittr_com/__pycache__/mit_t_r.cpython-312.pyc
Normal file
BIN
seek/mittr_com/__pycache__/mit_t_r.cpython-312.pyc
Normal file
Binary file not shown.
45
seek/mittr_com/content.py
Normal file
45
seek/mittr_com/content.py
Normal file
@ -0,0 +1,45 @@
|
||||
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 ArticleContent(ContentBase):
|
||||
def __init__(self, news: TNews):
|
||||
super().__init__(news)
|
||||
|
||||
def get_content(self):
|
||||
try:
|
||||
content_ = self.tab.s_ele('.content').text
|
||||
except ElementNotFoundError:
|
||||
content_ = 'not found element'
|
||||
return content_
|
||||
|
||||
|
||||
def get_content(information_source: TInformationSource) -> list:
|
||||
article_content = ArticleContent(information_source)
|
||||
result = article_content.get_content()
|
||||
article_content.finish()
|
||||
return result
|
||||
|
||||
|
||||
def content_task(news: TNews):
|
||||
logger.info(f'{news.title} news_task start execute at {datetime.datetime.now()}', )
|
||||
ofweek_com_ai = ArticleContent(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 = False
|
||||
news_.url = 'https://www.mittrchina.com/news/detail/14218'
|
||||
content = get_content(news_)
|
||||
logger.info(content)
|
||||
logger.info('Done.')
|
||||
63
seek/mittr_com/mit_t_r.py
Normal file
63
seek/mittr_com/mit_t_r.py
Normal file
@ -0,0 +1,63 @@
|
||||
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.seek_base import SeekBase
|
||||
from utils.time_utils import process_time
|
||||
|
||||
|
||||
class MittrChinaCom(SeekBase):
|
||||
def __init__(self, information_source: TInformationSource):
|
||||
super().__init__(information_source)
|
||||
|
||||
def get_news(self):
|
||||
news_result = []
|
||||
self.tab.wait.ele_displayed('.last-item')
|
||||
_news_list = self.tab.s_ele('.lastest-list').s_eles('.last-item')
|
||||
|
||||
for _news in _news_list:
|
||||
try:
|
||||
tnews = TNews()
|
||||
tnews.title = _news.s_ele('tag:a').text
|
||||
tnews.url = _news.s_ele('tag:a').link
|
||||
_time = _news.parent().s_ele('.time').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: {e} - Failed to find element in news item.")
|
||||
except Exception as e:
|
||||
logger.error(f'Unexpected error occurred: {e}')
|
||||
|
||||
return news_result
|
||||
|
||||
|
||||
def get_news(information_source: TInformationSource) -> list:
|
||||
mittr = MittrChinaCom(information_source)
|
||||
news_list = mittr.get_news()
|
||||
mittr.finish()
|
||||
return news_list
|
||||
|
||||
|
||||
def news_task(information_source: TInformationSource):
|
||||
logger.info(f'{information_source.title} news_task start execute at {datetime.datetime.now()}', )
|
||||
mittr = MittrChinaCom(information_source)
|
||||
mittr.do_seek_task()
|
||||
mittr.finish()
|
||||
logger.info(f'{information_source.title} news_task end execute at {datetime.datetime.now()}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger.info('This module is not for direct call!')
|
||||
information_source_ = TInformationSource()
|
||||
information_source_.is_static = False
|
||||
information_source_.url = 'https://www.mittrchina.com/'
|
||||
information_source_.title = '科技_麻省理工科技评论'
|
||||
news_task(information_source_)
|
||||
# news_list_ = get_news(information_source_)
|
||||
# for news in news_list_:
|
||||
# print(news)
|
||||
logger.info('Done.')
|
||||
Reference in New Issue
Block a user