From 37ee468185f89fcc4e8240ac87ace85e71fe8e48 Mon Sep 17 00:00:00 2001 From: FongMi Date: Thu, 15 Aug 2024 01:04:54 +0800 Subject: [PATCH] Update spider.py --- chaquo/src/main/python/base/spider.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/chaquo/src/main/python/base/spider.py b/chaquo/src/main/python/base/spider.py index 75597e39b..b56eb8f06 100644 --- a/chaquo/src/main/python/base/spider.py +++ b/chaquo/src/main/python/base/spider.py @@ -13,6 +13,9 @@ from com.github.catvod import Proxy class Spider(metaclass=ABCMeta): _instance = None + def __init__(self): + self.extend = '' + def __new__(cls, *args, **kwargs): if cls._instance: return cls._instance @@ -99,9 +102,21 @@ class Spider(metaclass=ABCMeta): def html(self, content): return etree.HTML(content) + def str2json(str): + return json.loads(str) + + def json2str(str): + return json.dumps(str, ensure_ascii=False) + def getProxyUrl(self, local=True): return f'{Proxy.getUrl(local)}?do=py' + def log(self, msg): + if isinstance(msg, dict) or isinstance(msg, list): + print(json.dumps(msg, ensure_ascii=False)) + else: + print(f'{msg}') + def getCache(self, key): value = self.fetch(f'http://127.0.0.1:{Proxy.getPort()}/cache?do=get&key={key}', timeout=5).text if len(value) > 0: