mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2025-12-26 04:48:05 +08:00
更新代码
This commit is contained in:
parent
bba6940cc8
commit
4999b47fee
@ -1,14 +1,57 @@
|
||||
from json import loads
|
||||
from re import compile
|
||||
from time import strftime
|
||||
|
||||
|
||||
class Explore:
|
||||
explore_data = compile(
|
||||
r'"currentTime":\d{13},"note":(.*?)}},"serverRequestInfo"')
|
||||
time_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def run(self, html: str):
|
||||
def run(self, html: str) -> dict:
|
||||
data = self.get_json_data(html)
|
||||
return self.extract_data(data)
|
||||
|
||||
def get_json_data(self, html: str) -> dict:
|
||||
data = self.explore_data.findall(html)
|
||||
return {} if len(data) != 1 else loads(data[0])
|
||||
|
||||
def extract_data(self, data: dict) -> dict:
|
||||
result = {}
|
||||
self.extract_interact_info(result, data)
|
||||
self.extract_tags(result, data)
|
||||
self.extract_info(result, data)
|
||||
self.extract_time(result, data)
|
||||
self.extract_user(result, data)
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def extract_interact_info(container: dict, data: dict):
|
||||
interact_info = data["interactInfo"]
|
||||
container["收藏数量"] = interact_info["collectedCount"]
|
||||
container["评论数量"] = interact_info["commentCount"]
|
||||
container["分享数量"] = interact_info["shareCount"]
|
||||
container["点赞数量"] = interact_info["likedCount"]
|
||||
|
||||
@staticmethod
|
||||
def extract_tags(container: dict, data: dict):
|
||||
tags = data["tagList"]
|
||||
container["作品标签"] = [i["name"] for i in tags]
|
||||
|
||||
@staticmethod
|
||||
def extract_info(container: dict, data: dict):
|
||||
container["作品ID"] = data["noteId"]
|
||||
container["作品标题"] = data["title"]
|
||||
container["作品描述"] = data["desc"]
|
||||
container["作品类型"] = {"video": "视频", "normal": "图文"}[data["type"]]
|
||||
|
||||
def extract_time(self, container: dict, data: dict):
|
||||
container["发布时间"] = strftime(self.time_format, data["time"])
|
||||
container["最后更新时间"] = strftime(
|
||||
self.time_format, data["lastUpdateTime"])
|
||||
|
||||
@staticmethod
|
||||
def extract_user(container: dict, data: dict):
|
||||
user = data["user"]
|
||||
container["作者昵称"] = user["nickname"]
|
||||
container["作者ID"] = user["userId"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user