Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一个图片笔记原图获取404的bug修复方法 #145

Open
Jeffrey-deng opened this issue Feb 9, 2025 · 0 comments
Open

一个图片笔记原图获取404的bug修复方法 #145

Jeffrey-deng opened this issue Feb 9, 2025 · 0 comments

Comments

@Jeffrey-deng
Copy link

现在有些图片获取的原图链接可能会报 404

例如如下链接(包含 notes_pre_post )
http://sns-webpic-qc.xhscdn.com/202502091552/692128172967b167daf2193fb398949c/notes_pre_post/1040g3k831chsvi310s704a7j5nkdj1mv2v81c8g!nd_dft_wlteh_webp_3

如果使用下面方法获取,则会报404:
http://sns-img-hw.xhscdn.com/1040g3k831chsvi310s704a7j5nkdj1mv2v81c8g

实际它的原图应该是:
http://sns-img-hw.xhscdn.com/notes_pre_post/1040g3k831chsvi310s704a7j5nkdj1mv2v81c8g

https://ci.xiaohongshu.com/notes_pre_post/1040g3k831chsvi310s704a7j5nkdj1mv2v81c8g

修复代码为,修改 help.pyget_trace_id 方法
https://github.com/ReaJason/xhs/blob/613036c431f1f8b68d6d4e8125e20629679bee41/xhs/help.py#L97

def get_trace_id(img_url: str):
    trace_id = img_url.split("/")[-1].split("!")[0]
    if "spectrum" in img_url:
        return "spectrum/" + trace_id
    # 增加此处代码
    if "notes_pre_post" in img_url:
        return "notes_pre_post/" + trace_id
    return trace_id

临时修改方法:

def get_trace_id(img_url: str):
    trace_id = img_url.split("/")[-1].split("!")[0]
    if "spectrum" in img_url:
        return "spectrum/" + trace_id
    if "notes_pre_post" in img_url:
        return "notes_pre_post/" + trace_id
    return trace_id

xhs.help.get_trace_id = get_trace_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant