小红书web search_id

没啥写的,我没验证,大家自己试试

js:

function F(){
    var timestamp = new Date().getTime().toString();
    if (timestamp.length < 13) {
      timestamp = timestamp.padEnd(13, "0");
    }
    return timestamp
}

function J() {
            var e;
            var t = BigInt(F())
              , r = BigInt(Math.ceil(2147483646 * Math.random()));
            return t <<= BigInt(64),
            (t += r).toString(36)
        }
console.log(J())

python:

import time
import random
import math

def F():
    timestamp = str(math.floor(time.time() * 1000))
    if len(timestamp) < 13:
        timestamp = timestamp.ljust(13, "0")
    return timestamp

def J():
    t = int(F())
    r = random.randint(1, 2147483646)
    t <<= 64
    t += r
    return base36encode(t)

def base36encode(number):
    digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    base36 = ""
    while number:
        number, i = divmod(number, 36)
        base36 = digits[i] + base36
    return base36.lower()

print(J())

关于搜索中文编码的问题:

requests传出去后uincode编码了,所以keyword异常。

需要转换下:json.dumps(data,separators=(",", ":"),ensure_ascii=False).encode('utf-8')

注意content-type

def saerch(keyword,web_session,a1):
    headers = {
        "accept":"application/json, text/plain, */*",
        "cache-control":"no-cache",
        "content-type":"application/json;charset=UTF-8",
        "cookie":f"a1={a1}; web_session={web_session};",
        "origin":"https://www.xiaohongshu.com",
        "referer":"https://www.xiaohongshu.com/",
        "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
        "x-b3-traceid":"a31fffc0ee4f5d8f",
        "x-s-common":"",
    }
    data = {"keyword":keyword,"page":1,"page_size":20,"search_id":J(),"sort":"general","note_type":0}
    exc = execjs.compile(open('xs20230531.js', 'r', encoding='utf-8').read())
    xs_xt = exc.call('get_xs','/api/sns/web/v1/search/notes',data,a1)
    xs_xt['X-t'] = str(xs_xt['X-t'])
    headers.update(xs_xt)
    feed = 'https://edith.xiaohongshu.com/api/sns/web/v1/search/notes'
    print(requests.post(url=feed,data=json.dumps(data,separators=(",", ":"),ensure_ascii=False).encode('utf-8'), headers=headers).text)
点赞
  1. 会飞的热带鱼说道:
    Safari iPhone iOS 16.5
    爬下来的数据没有减值和嵌套里面的值,要怎么拿到这些值
    1. DGT174说道:
      Google Chrome Windows 10
      大佬解决了吗
  2. liqunqun说道:
    Google Chrome Mac OS X 10.15.7
    想问那个.js的文件里面存放什么呀
  3. yuchen1573说道:
    Google Chrome Windows 10
    感谢大佬的分享!然后我有个小问题,这个search_id好像是跟搜索词和页数有关的吧?但是我看你生成的方法里,并没涉及到?
  4. xlxl说道:
    Google Chrome Windows 10
    这个接口调用多了,当天的账号会被限制,返回这个{"code":-1,"success":false,"msg":"网页版搜索次数已达今日上限,可以去小红书App继续搜索","data":{"has_more":false}},但是我用另外一个号在浏览器里手动搜索浏览刷不会出现这个限制(手动刷的次数比调用接口次数多),这个xhs是不是其他接口的做了上报校验,大佬有遇到过这个情况吗
    1. xlxl说道:
      Google Chrome Windows 10
      直接请求搜索接口次数多了出现“”网页版搜索次数已达今日上限,可以去小红书App继续搜索“”这个提示,已经把请求间隔放了3-8秒的间隔了
      1. DGT174说道:
        Google Chrome Windows 10
        大佬可以加个联系方式交流一下嘛?
    2. 大鱼说道:
      Google Chrome Windows 10
      大佬,我也遇到了这个问题,{"code":-1,"success":false},你是怎么解决的呢
    3. lyx说道:
      Google Chrome Windows 10
      大概搜索三十次左右就会触发上线
  5. 派大鑫说道:
    Google Chrome Windows 10
    感谢大佬!!
  6. shark说道:
    Google Chrome Mac OS X 10.15.7
    我感觉应该是 keyword的问题,有没有大佬知道小红书的搜索接口 keyword参数是咋编码的 :guai:
    1. Lx Lx说道:
      Google Chrome Windows 10
      json.dumps(data,separators=(",", ":"),ensure_ascii=False).encode('utf-8')
  7. shark说道:
    Google Chrome Mac OS X 10.15.7
    大佬 search接口我的keyword字段中文会进行 两次encodeURIComponent,能请求成功。但是每次返回的结果都和我搜索的关键词不匹配,不知道是啥原因
    1. Lx Lx说道:
      Google Chrome Windows 10
      不清楚 :a: ,我没有测过搜索
  8. shark说道:
    Google Chrome Mac OS X 10.15.7
    大佬牛逼!!

发表回复