@@ -120,7 +120,7 @@ def analyse_jm_search_html(cls, html: str) -> JmSearchPage:
120120 @classmethod
121121 def reflect_new_instance (cls , html : str , cls_field_prefix : str , clazz : type ):
122122
123- def match_field (field_key : str , pattern : Union [Pattern , List [Pattern ]], text ):
123+ def match_field (field_name : str , pattern : Union [Pattern , List [Pattern ]], text ):
124124
125125 if isinstance (pattern , list ):
126126 # 如果是 pattern 是 List[re.Pattern],
@@ -136,7 +136,7 @@ def match_field(field_key: str, pattern: Union[Pattern, List[Pattern]], text):
136136
137137 return last_pattern .findall (text )
138138
139- if field_key .endswith ("_list" ):
139+ if field_name .endswith ("_list" ):
140140 return pattern .findall (text )
141141 else :
142142 match = pattern .search (text )
@@ -283,9 +283,15 @@ class JmPageTool:
283283 r'</div>'
284284 )
285285
286- # 收藏页面的文件夹收藏总数
286+ # 收藏夹的收藏总数
287287 pattern_html_favorite_total = compile (r' : (\d+)[^/]*/\D*(\d+)' )
288288
289+ # 所有的收藏夹
290+ pattern_html_favorite_folder_list = [
291+ compile (r'<select class="user-select" name="movefolder-fid">([\s\S]*)</select>' ),
292+ compile (r'<option value="(\d+)">([^<]*?)</option>' )
293+ ]
294+
289295 @classmethod
290296 def parse_html_to_search_page (cls , html : str ) -> JmSearchPage :
291297 # 1. 检查是否失败
@@ -327,15 +333,18 @@ def parse_html_to_favorite_page(cls, html: str) -> JmFavoritePage:
327333 '未匹配到收藏夹的本子总数' ,
328334 ))
329335
330- # 收藏页面的本子结果
336+ # 收藏夹的本子结果
331337 content = cls .pattern_html_favorite_content .findall (html )
332338 content = [
333339 (aid , {'name' : atitle })
334340 for aid , atitle in content
335341 ]
336342
337- # 暂不实现匹配文件夹列表,感觉没什么意义..
338- folder_list = []
343+ # 匹配收藏夹列表
344+ p1 , p2 = cls .pattern_html_favorite_folder_list
345+ folder_list_text = PatternTool .require_match (html , p1 , '未匹配到收藏夹列表' )
346+ folder_list_raw = p2 .findall (folder_list_text )
347+ folder_list = [{'name' : fname , 'FID' : fid } for fid , fname in folder_list_raw ]
339348
340349 return JmFavoritePage (content , folder_list , total )
341350
@@ -397,8 +406,8 @@ def parse_api_to_favorite_page(cls, data: DictModel) -> JmFavoritePage:
397406 "FID": "123",
398407 "1": "456",
399408 "UID": "456",
400- "2": "文件夹名 ",
401- "name": "文件夹名 "
409+ "2": "收藏夹名 ",
410+ "name": "收藏夹名 "
402411 }
403412 ],
404413 "total": "87",
@@ -408,7 +417,7 @@ def parse_api_to_favorite_page(cls, data: DictModel) -> JmFavoritePage:
408417 total : int = int (data .total )
409418 # count: int = int(data.count)
410419 content = cls .adapt_content (data .list )
411- folder_list = data .folder_list
420+ folder_list = data .get ( ' folder_list' , [])
412421
413422 return JmFavoritePage (content , folder_list , total )
414423
0 commit comments