2024-10-19 16:43:25 +00:00
|
|
|
# 声明:本代码仅供学习和研究目的使用。使用者应遵守以下原则:
|
|
|
|
# 1. 不得用于任何商业用途。
|
|
|
|
# 2. 使用时应遵守目标平台的使用条款和robots.txt规则。
|
|
|
|
# 3. 不得进行大规模爬取或对平台造成运营干扰。
|
|
|
|
# 4. 应合理控制请求频率,避免给目标平台带来不必要的负担。
|
|
|
|
# 5. 不得用于任何非法或不当的用途。
|
|
|
|
#
|
|
|
|
# 详细许可条款请参阅项目根目录下的LICENSE文件。
|
|
|
|
# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。
|
|
|
|
|
|
|
|
|
2023-06-27 15:38:30 +00:00
|
|
|
from abc import ABC, abstractmethod
|
2023-12-24 16:02:11 +00:00
|
|
|
from typing import Dict, Optional
|
|
|
|
|
|
|
|
from playwright.async_api import BrowserContext, BrowserType
|
2023-06-27 15:38:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbstractCrawler(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
async def start(self):
|
2024-09-02 13:45:12 +00:00
|
|
|
"""
|
|
|
|
start crawler
|
|
|
|
"""
|
2023-06-27 15:38:30 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-07-29 07:35:40 +00:00
|
|
|
async def search(self):
|
2024-09-02 13:45:12 +00:00
|
|
|
"""
|
|
|
|
search
|
|
|
|
"""
|
2023-06-27 15:38:30 +00:00
|
|
|
pass
|
|
|
|
|
2023-12-24 16:02:11 +00:00
|
|
|
@abstractmethod
|
|
|
|
async def launch_browser(self, chromium: BrowserType, playwright_proxy: Optional[Dict], user_agent: Optional[str],
|
|
|
|
headless: bool = True) -> BrowserContext:
|
2024-09-02 13:45:12 +00:00
|
|
|
"""
|
|
|
|
launch browser
|
|
|
|
:param chromium: chromium browser
|
|
|
|
:param playwright_proxy: playwright proxy
|
|
|
|
:param user_agent: user agent
|
|
|
|
:param headless: headless mode
|
|
|
|
:return: browser context
|
|
|
|
"""
|
2023-12-24 16:02:11 +00:00
|
|
|
pass
|
|
|
|
|
2023-06-27 15:38:30 +00:00
|
|
|
|
|
|
|
class AbstractLogin(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
async def begin(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def login_by_qrcode(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def login_by_mobile(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def login_by_cookies(self):
|
|
|
|
pass
|
2024-01-14 14:06:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbstractStore(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
async def store_content(self, content_item: Dict):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def store_comment(self, comment_item: Dict):
|
|
|
|
pass
|
2024-03-01 17:49:42 +00:00
|
|
|
|
|
|
|
# TODO support all platform
|
|
|
|
# only xhs is supported, so @abstractmethod is commented
|
2024-07-18 12:11:51 +00:00
|
|
|
@abstractmethod
|
2024-03-01 17:49:42 +00:00
|
|
|
async def store_creator(self, creator: Dict):
|
|
|
|
pass
|
2024-03-30 13:27:25 +00:00
|
|
|
|
2024-05-23 14:15:14 +00:00
|
|
|
|
2024-04-09 09:21:52 +00:00
|
|
|
class AbstractStoreImage(ABC):
|
2024-05-23 14:15:14 +00:00
|
|
|
# TODO: support all platform
|
2024-04-09 09:21:52 +00:00
|
|
|
# only weibo is supported
|
|
|
|
# @abstractmethod
|
|
|
|
async def store_image(self, image_content_item: Dict):
|
|
|
|
pass
|
2024-03-30 13:27:25 +00:00
|
|
|
|
2024-05-23 14:15:14 +00:00
|
|
|
|
2024-04-13 12:18:04 +00:00
|
|
|
class AbstractApiClient(ABC):
|
2024-03-30 13:27:25 +00:00
|
|
|
@abstractmethod
|
|
|
|
async def request(self, method, url, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def update_cookies(self, browser_context: BrowserContext):
|
|
|
|
pass
|