ReaJason / xhs

基于小红书 Web 端进行的请求封装。https://reajason.github.io/xhs/
MIT License
946 stars 279 forks source link

[get_note_by_id] 现在总是 return {} #107

Closed bensonz closed 2 months ago

bensonz commented 3 months ago

不太确定小红书是不是改了 api 接口, 现在的get_note_by_id 是空的.

    def get_note_by_id(self, note_id: str):
        """
        :param note_id: note_id you want to fetch
        :type note_id: str
        :rtype: dict
        """
        data = {"source_note_id": note_id, "image_scenes": ["CRD_WM_WEBP"]}
        uri = "/api/sns/web/v1/feed"
        res = self.post(uri, data)
        return res["items"][0]["note_card"] #<<< 这里会报错, 因为 res 是空的

已知 sign 没有问题, 因为可以get_home_feed

Screenshot 2024-04-28 at 12 53 24
bensonz commented 3 months ago

emm, get_note_by_id_from_html 这个可以用 但是之前那个咋突然没了呢?

glorysaladin commented 3 months ago

get_note_by_id_from_html

get_note_by_id一样获取的是空的, 看之前的issue说是触发了小红书的验证码了,现在应该是没办法绕过去。

hjhjhghghg commented 3 months ago

同上,这两天get_note_by_id时好时坏,但是from_html是好的

Gh-mean commented 3 months ago

经过测试,目前所有note和user的请求均461,返回头中包含验证码uuid。使用该id请求验证码滑过后再请求依旧461

bensonz commented 3 months ago

opps 刚看到, 前面有 issue 提过了. Author 建议多试几次. 现在看来这个验证码 uuid 是绕不过去了.

glorysaladin commented 3 months ago

from html 获取到的图片不清晰

bensonz commented 3 months ago

妈的我怀疑这里被小红书监控了, 昨天 get by html 还行, 今天就 json 解析失败.

bensonz commented 3 months ago

有没有什么微信群, 可以一起看看什么情况 @ReaJason

ReaJason commented 3 months ago

这么恐怖嘛

ReaJason commented 3 months ago

更新了 0.2.12 版本,先尝试用 get_note_by_id_from_html 替代吧,目前没时间研究验证码, 如果有好的思路欢迎在 https://github.com/ReaJason/xhs/discussions/109 讨论

bensonz commented 3 months ago

很神奇, 如果把 chromise 的 headless = False, 就可以了.

browser = chromium.launch(headless=False)

一旦设置成 true, 就会 redirect 到 website-login/captcha 回头再看看有没有什么解决方案, 不应该啊.

Gh-mean commented 3 months ago

很神奇, 如果把 chromise 的 headless = False, 就可以了.

browser = chromium.launch(headless=False)

一旦设置成 true, 就会 redirect 到 website-login/captcha 回头再看看有没有什么解决方案, 不应该啊.

maybe无头模式被检测了?

ReaJason commented 3 months ago

from html 获取到的图片不清晰

直接通过 xhs.help.get_imgs_url_from_note(note) 把获取到的笔记传进去应该是无水印的图片了

hjhjhghghg commented 3 months ago

from html 获取到的图片不清晰

直接通过 xhs.help.get_imgs_url_from_note(note) 把获取到的笔记传进去应该是无水印的图片了

这个接口好像也有问题了 我的代码:#根据笔记id下载素材 @app.route("/save_files_from_note_id", methods=["GET"]) def save_files_from_note_id(): noteid = request.args.get('noteid') file_dir = r"C:\Users\az\Pictures\xhs_samples" if not noteid: return "noteid is required", 400 id = request.args.get('id') if not id: return jsonify({"error": "account_id is required"}), 400

# 从数据库中查找匹配的账户记录
account = Account.query.filter_by(id=id).first()
if account:
    xhs_client = XhsClient(account.cookie, sign=sign)  # 自定义代理
    save_res = xhs_client.save_files_from_note_id(noteid,file_dir)
return save_res

返回: [2024-04-30 04:35:50,415] ERROR in app: Exception on /save_files_from_note_id [GET] Traceback (most recent call last): File "C:\Users\az\PycharmProjects\xhs\venv\lib\site-packages\flask\app.py", line 1473, in wsgi_app response = self.full_dispatch_request() File "C:\Users\az\PycharmProjects\xhs\venv\lib\site-packages\flask\app.py", line 883, in full_dispatch_request return self.finalize_request(rv) File "C:\Users\az\PycharmProjects\xhs\venv\lib\site-packages\flask\app.py", line 902, in finalize_request response = self.make_response(rv) File "C:\Users\az\PycharmProjects\xhs\venv\lib\site-packages\flask\app.py", line 1174, in make_response raise TypeError( TypeError: The view function for 'save_files_from_note_id' did not return a valid response. The function either returned None or ended without a return statement. 我在help的方法中打印了一下: def get_imgs_url_from_note(note) -> list: """the return type is [img1_url, img2_url, ...]""" imgs = note["image_list"] if not len(imgs): return [] img_urls = [get_img_url_by_trace_id(get_trace_id(img["info_list"][0]["url"])) for img in imgs] print("图片地址:"+img_urls) return img_urls 图片地址:https://sns-img-hw.xhscdn.com/1040g0083124l719t426g5petcreh92d6dgrdrd0?imageView2/format/png None 是不是因为这个None导致的问题 我还打印了note: {'cursor_score': '', 'items': [{'id': '662e0c16000000000103126f', 'model_type': 'note', 'note_card': {'type': 'normal', 'last_update_time': 1714293783000, 'share_info': {'un_share': False}, 'illegal_info': {'desc': '请谨慎甄别内容信息,注意个人安全', 'left_icon': 'https://picasso-static.xiaohongshu.com/fe-platfrom/bc740cc162107169b504c4c1e5ee35f92eaa8456.png'}, 'title': '福州五一搭子集合 限女', 'tag_list': [{'id': '653335510000000003012030', 'name': '福州女生搭子', 'type': 'topic'}, {'type': 'topic', 'id': '64110ed3000000001803812c', 'name': '求女生搭子'}, {'id': '645c9ae9000000001a00578d', 'name': '找女生搭子', 'type': 'topic'}, {'name': '女生饭搭子', 'type': 'topic', 'id': '64afa1a6000000002502396c'}, {'id': '6428096b000000000901b7e1', 'name': '女生找搭子', 'type': 'topic'}, {'type': 'topic', 'id': '62c3d9df00000000010054d2', 'name': '聊天搭子'}, {'id': '6246a703000000000101f676', 'name': '找饭搭子', 'type': 'topic'}, {'id': '5c5f671b000000000d0299e5', 'name': '一起玩', 'type': 'topic'}, {'name': '约饭', 'type': 'topic', 'id': '5cb9b7fc000000000f03a388'}, {'id': '5eb7ead70000000001007241', 'name': '组局', 'type': 'topic'}, {'id': '64140026000000000901b34d', 'name': '女生搭子', 'type': 'topic'}], 'at_user_list': [], 'note_id': '662e0c16000000000103126f', 'desc': ' ', 'user': {'user_id': '65dd66dd00000000050089a6', 'nickname': '福州-惊喜搭子', 'avatar': 'https://sns-avatar-qc.xhscdn.com/avatar/1040g2jo3124k7g3v3s5g5petcreh92d6fd0id0g'}, 'time': 1714293782000, 'ip_location': '福建', 'interact_info': {'share_count': '0', 'followed': False, 'relation': 'none', 'liked': False, 'liked_count': '5', 'collected': False, 'collected_count': '0', 'comment_count': '1'}, 'image_list': [{'info_list': [{'image_scene': 'CRD_WM_WEBP', 'url': 'http://sns-webpic-qc.xhscdn.com/202404300435/0727640d018a034bcee4408eba1e487b/1040g0083124l719t426g5petcreh92d6dgrdrd0!nd_whgt34_webp_wm_1'}], 'file_id': '', 'height': 2560, 'width': 1920, 'url': '', 'trace_id': ''}]}}], 'current_time': 1714422950766}