Spaces:
Running
Running
rogerxavier
commited on
Update server/resource.py
Browse files- server/resource.py +8 -4
server/resource.py
CHANGED
@@ -8,17 +8,21 @@ class Resource:
|
|
8 |
def __init__(self, url: str):
|
9 |
self.url = url
|
10 |
self.cutted_str: str
|
11 |
-
self.
|
|
|
12 |
self._get_resource()
|
13 |
|
14 |
def _get_resource(self) -> None:
|
15 |
try:
|
16 |
request = requests.get(self.url, headers=headers)
|
17 |
self.cutted_str = request.text
|
18 |
-
self.
|
|
|
19 |
except Exception as e:
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
def get_encoded_data(self) -> str:
|
24 |
try:
|
|
|
8 |
def __init__(self, url: str):
|
9 |
self.url = url
|
10 |
self.cutted_str: str
|
11 |
+
self.cutted_str_save_file = 'subscribe_data_encoded.txt' # 添加一个文件路径存储前得到的 cutted_str
|
12 |
+
self.previous_cutted_str:str
|
13 |
self._get_resource()
|
14 |
|
15 |
def _get_resource(self) -> None:
|
16 |
try:
|
17 |
request = requests.get(self.url, headers=headers)
|
18 |
self.cutted_str = request.text
|
19 |
+
with open(self.cutted_str_save_file,'w')as f:
|
20 |
+
f.write(self.cutted_str)
|
21 |
except Exception as e:
|
22 |
+
with open(self.cutted_str_save_file,'r')as f:
|
23 |
+
self.previous_cutted_str=f.read()
|
24 |
+
print(f"请求失败,使用之前的cutted_str",self.previous_cutted_str)
|
25 |
+
|
26 |
|
27 |
def get_encoded_data(self) -> str:
|
28 |
try:
|