feat: add abstract api client to all platform
This commit is contained in:
parent
67ec49498a
commit
e950e0d6e3
|
@ -55,3 +55,17 @@ class AbstractStore(ABC):
|
||||||
# @abstractmethod
|
# @abstractmethod
|
||||||
async def store_creator(self, creator: Dict):
|
async def store_creator(self, creator: Dict):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class AbstactApiClient(ABC):
|
||||||
|
@abstractmethod
|
||||||
|
async def request(self, method, url, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def update_cookies(self, browser_context: BrowserContext):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
async def pong(self):
|
||||||
|
pass
|
||||||
|
|
|
@ -10,6 +10,7 @@ from urllib.parse import urlencode
|
||||||
import httpx
|
import httpx
|
||||||
from playwright.async_api import BrowserContext, Page
|
from playwright.async_api import BrowserContext, Page
|
||||||
|
|
||||||
|
from base.base_crawler import AbstactApiClient
|
||||||
from tools import utils
|
from tools import utils
|
||||||
|
|
||||||
from .exception import DataFetchError
|
from .exception import DataFetchError
|
||||||
|
@ -17,7 +18,7 @@ from .field import CommentOrderType, SearchOrderType
|
||||||
from .help import BilibiliSign
|
from .help import BilibiliSign
|
||||||
|
|
||||||
|
|
||||||
class BilibiliClient:
|
class BilibiliClient(AbstactApiClient):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import execjs
|
||||||
import httpx
|
import httpx
|
||||||
from playwright.async_api import BrowserContext, Page
|
from playwright.async_api import BrowserContext, Page
|
||||||
|
|
||||||
|
from base.base_crawler import AbstactApiClient
|
||||||
from tools import utils
|
from tools import utils
|
||||||
from var import request_keyword_var
|
from var import request_keyword_var
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ from .exception import *
|
||||||
from .field import *
|
from .field import *
|
||||||
|
|
||||||
|
|
||||||
class DOUYINClient:
|
class DOUYINClient(AbstactApiClient):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
timeout=30,
|
timeout=30,
|
||||||
|
|
|
@ -16,8 +16,8 @@ from var import crawler_type_var
|
||||||
|
|
||||||
from .client import DOUYINClient
|
from .client import DOUYINClient
|
||||||
from .exception import DataFetchError
|
from .exception import DataFetchError
|
||||||
from .login import DouYinLogin
|
|
||||||
from .field import PublishTimeType
|
from .field import PublishTimeType
|
||||||
|
from .login import DouYinLogin
|
||||||
|
|
||||||
|
|
||||||
class DouYinCrawler(AbstractCrawler):
|
class DouYinCrawler(AbstractCrawler):
|
||||||
|
|
|
@ -8,13 +8,14 @@ import httpx
|
||||||
from playwright.async_api import BrowserContext, Page
|
from playwright.async_api import BrowserContext, Page
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
from base.base_crawler import AbstactApiClient
|
||||||
from tools import utils
|
from tools import utils
|
||||||
|
|
||||||
from .exception import DataFetchError
|
from .exception import DataFetchError
|
||||||
from .graphql import KuaiShouGraphQL
|
from .graphql import KuaiShouGraphQL
|
||||||
|
|
||||||
|
|
||||||
class KuaiShouClient:
|
class KuaiShouClient(AbstactApiClient):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from typing import Callable, Dict, List, Optional, Union, Any
|
from typing import Any, Callable, Dict, List, Optional, Union
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from playwright.async_api import BrowserContext, Page
|
from playwright.async_api import BrowserContext, Page
|
||||||
|
|
||||||
|
from base.base_crawler import AbstactApiClient
|
||||||
from tools import utils
|
from tools import utils
|
||||||
|
|
||||||
from .exception import DataFetchError, IPBlockError
|
from .exception import DataFetchError, IPBlockError
|
||||||
|
@ -14,7 +15,7 @@ from .field import SearchNoteType, SearchSortType
|
||||||
from .help import get_search_id, sign
|
from .help import get_search_id, sign
|
||||||
|
|
||||||
|
|
||||||
class XiaoHongShuClient:
|
class XiaoHongShuClient(AbstactApiClient):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
|
|
Loading…
Reference in New Issue