42 lines
856 B
Python
42 lines
856 B
Python
# coding=utf-8
|
|
import abc
|
|
import logging
|
|
|
|
class BaseCrawler(abc.ABC):
|
|
"""
|
|
所有小程序爬虫的基类。
|
|
定义了标准的生命周期方法。
|
|
"""
|
|
|
|
def __init__(self, service=None):
|
|
self.logger = logging.getLogger(self.__class__.__name__)
|
|
self.service = service
|
|
|
|
@abc.abstractmethod
|
|
async def start(self):
|
|
"""
|
|
启动爬虫的主入口。
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def open_app(self):
|
|
"""
|
|
打开目标小程序。
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def crawl_list(self):
|
|
"""
|
|
爬取列表页。
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def crawl_detail(self, station_info):
|
|
"""
|
|
爬取详情页。
|
|
"""
|
|
pass
|