mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
更新代码
This commit is contained in:
@@ -9,24 +9,24 @@ class Explore:
|
|||||||
time_format = "%Y-%m-%d %H:%M:%S"
|
time_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
|
||||||
def run(self, html: str) -> dict:
|
def run(self, html: str) -> dict:
|
||||||
data = self.get_json_data(html)
|
data = self.__get_json_data(html)
|
||||||
return self.extract_data(data)
|
return self.__extract_data(data)
|
||||||
|
|
||||||
def get_json_data(self, html: str) -> dict:
|
def __get_json_data(self, html: str) -> dict:
|
||||||
data = self.explore_data.findall(html)
|
data = self.explore_data.findall(html)
|
||||||
return {} if len(data) != 1 else loads(data[0])
|
return {} if len(data) != 1 else loads(data[0])
|
||||||
|
|
||||||
def extract_data(self, data: dict) -> dict:
|
def __extract_data(self, data: dict) -> dict:
|
||||||
result = {}
|
result = {}
|
||||||
self.extract_interact_info(result, data)
|
self.__extract_interact_info(result, data)
|
||||||
self.extract_tags(result, data)
|
self.__extract_tags(result, data)
|
||||||
self.extract_info(result, data)
|
self.__extract_info(result, data)
|
||||||
self.extract_time(result, data)
|
self.__extract_time(result, data)
|
||||||
self.extract_user(result, data)
|
self.__extract_user(result, data)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extract_interact_info(container: dict, data: dict):
|
def __extract_interact_info(container: dict, data: dict):
|
||||||
interact_info = data["interactInfo"]
|
interact_info = data["interactInfo"]
|
||||||
container["收藏数量"] = interact_info["collectedCount"]
|
container["收藏数量"] = interact_info["collectedCount"]
|
||||||
container["评论数量"] = interact_info["commentCount"]
|
container["评论数量"] = interact_info["commentCount"]
|
||||||
@@ -34,24 +34,24 @@ class Explore:
|
|||||||
container["点赞数量"] = interact_info["likedCount"]
|
container["点赞数量"] = interact_info["likedCount"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extract_tags(container: dict, data: dict):
|
def __extract_tags(container: dict, data: dict):
|
||||||
tags = data["tagList"]
|
tags = data["tagList"]
|
||||||
container["作品标签"] = [i["name"] for i in tags]
|
container["作品标签"] = [i["name"] for i in tags]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extract_info(container: dict, data: dict):
|
def __extract_info(container: dict, data: dict):
|
||||||
container["作品ID"] = data["noteId"]
|
container["作品ID"] = data["noteId"]
|
||||||
container["作品标题"] = data["title"]
|
container["作品标题"] = data["title"]
|
||||||
container["作品描述"] = data["desc"]
|
container["作品描述"] = data["desc"]
|
||||||
container["作品类型"] = {"video": "视频", "normal": "图文"}[data["type"]]
|
container["作品类型"] = {"video": "视频", "normal": "图文"}[data["type"]]
|
||||||
|
|
||||||
def extract_time(self, container: dict, data: dict):
|
def __extract_time(self, container: dict, data: dict):
|
||||||
container["发布时间"] = strftime(self.time_format, data["time"])
|
container["发布时间"] = strftime(self.time_format, data["time"])
|
||||||
container["最后更新时间"] = strftime(
|
container["最后更新时间"] = strftime(
|
||||||
self.time_format, data["lastUpdateTime"])
|
self.time_format, data["lastUpdateTime"])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def extract_user(container: dict, data: dict):
|
def __extract_user(container: dict, data: dict):
|
||||||
user = data["user"]
|
user = data["user"]
|
||||||
container["作者昵称"] = user["nickname"]
|
container["作者昵称"] = user["nickname"]
|
||||||
container["作者ID"] = user["userId"]
|
container["作者ID"] = user["userId"]
|
||||||
|
|||||||
@@ -30,20 +30,25 @@ class XHS:
|
|||||||
if cookie:
|
if cookie:
|
||||||
self.headers["Cookie"] = cookie
|
self.headers["Cookie"] = cookie
|
||||||
|
|
||||||
def get_image(self, url: str, download=False):
|
def get_image(self, container: dict, html: str, download):
|
||||||
urls = self.image.get_image_link(url)
|
urls = self.image.get_image_link(html)
|
||||||
if download:
|
if download:
|
||||||
self.download.run(urls)
|
self.download.run(urls)
|
||||||
return urls
|
container["下载地址"] = urls
|
||||||
|
|
||||||
def get_video(self, url: str, download=False):
|
def get_video(self, container: dict, html: str, download):
|
||||||
url = self.video.get_video_link(url)
|
url = self.video.get_video_link(html)
|
||||||
if download:
|
if download:
|
||||||
self.download.run([url])
|
self.download.run([url])
|
||||||
return url
|
container["下载地址"] = url
|
||||||
|
|
||||||
def extract(self, url: str):
|
def extract(self, url: str, download=False) -> dict:
|
||||||
html = self.html.get_html(url)
|
html = self.html.get_html(url)
|
||||||
if not html:
|
if not html:
|
||||||
return None
|
return {}
|
||||||
self.explore.run(html)
|
data = self.explore.run(html)
|
||||||
|
if data["作品类型"] == "视频":
|
||||||
|
self.get_video(data, html, download)
|
||||||
|
else:
|
||||||
|
self.get_image(data, html, download)
|
||||||
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user