mirror of
https://github.com/JoeanAmier/XHS-Downloader.git
synced 2026-03-22 06:57:16 +08:00
更新代码
This commit is contained in:
16
main.py
16
main.py
@@ -1,16 +1,10 @@
|
||||
# 这是一个示例 Python 脚本。
|
||||
|
||||
# 按 Shift+F10 执行或将其替换为您的代码。
|
||||
# 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。
|
||||
from source import get_image_link
|
||||
|
||||
|
||||
def print_hi(name):
|
||||
# 在下面的代码行中使用断点来调试脚本。
|
||||
print(f'Hi, {name}') # 按 Ctrl+F8 切换断点。
|
||||
def example():
|
||||
demo = "https://www.xiaohongshu.com/explore/64a3a5170000000031008914"
|
||||
print(get_image_link(demo))
|
||||
|
||||
|
||||
# 按装订区域中的绿色按钮以运行脚本。
|
||||
if __name__ == '__main__':
|
||||
print_hi('PyCharm')
|
||||
|
||||
# 访问 https://www.jetbrains.com/help/pycharm/ 获取 PyCharm 帮助
|
||||
example()
|
||||
|
||||
20
source/Html.py
Normal file
20
source/Html.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import requests
|
||||
|
||||
HEADERS = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203",
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
"Accept-Language": "zh-CN,zh;q=0.9",
|
||||
"Cache-Control": "no-cache",
|
||||
}
|
||||
|
||||
|
||||
def get_html(url, params=None, proxies=None, timeout=10, **kwargs):
|
||||
response = requests.get(
|
||||
url,
|
||||
params=params,
|
||||
proxies=proxies,
|
||||
timeout=timeout,
|
||||
headers=HEADERS,
|
||||
**kwargs)
|
||||
return response.text
|
||||
12
source/Image.py
Normal file
12
source/Image.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import re
|
||||
|
||||
API = "https://sns-img-qc.xhscdn.com/"
|
||||
ID = re.compile(r'"traceId":"(.*?)"')
|
||||
|
||||
|
||||
def get_id(html: str):
|
||||
return ID.findall(html)
|
||||
|
||||
|
||||
def generate_url(ids: list):
|
||||
return [API + i for i in ids]
|
||||
14
source/__init__.py
Normal file
14
source/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from .Html import get_html
|
||||
from .Image import generate_url
|
||||
from .Image import get_id
|
||||
|
||||
|
||||
def get_image_link(url: str, params=None, proxies=None, timeout=10, **kwargs):
|
||||
html = get_html(
|
||||
url,
|
||||
params=params,
|
||||
proxies=proxies,
|
||||
timeout=timeout,
|
||||
**kwargs)
|
||||
ids = get_id(html)
|
||||
return generate_url(ids)
|
||||
Reference in New Issue
Block a user