👋 Hi there,I'm ReaJason
- 🔥I'm a programming amateur.
- ❄I'm learning Java Web Cyber Security.
- ⚡I'm working on Java(RASP).
- 📫contact me by [email protected].
基于小红书 Web 端进行的请求封装。https://reajason.github.io/xhs/
License: MIT License
部分笔记在web端会出现-510001,"当前内容无法展示",但是实际在app端可以查看,这种情况可以获取吗?
脚本中只修改了 cokkie,设置了a1,webID,web_session三个参数,有以下报错:
python example/basic_usage.py
Traceback (most recent call last):
File "/Users/echooo/Documents/Code/my_repo/周末计划生成器/xhs/example/basic_usage.py", line 50, in
note_info = xhs_client.get_note_by_id("64c27f08000000001701967a")
File "/opt/homebrew/lib/python3.9/site-packages/xhs/core.py", line 201, in get_note_by_id
res = self.post(uri, data)
File "/opt/homebrew/lib/python3.9/site-packages/xhs/core.py", line 187, in post
self._pre_headers(uri, data, is_creator=is_creator)
File "/opt/homebrew/lib/python3.9/site-packages/xhs/core.py", line 155, in _pre_headers
self.sign(
File "/Users/echooo/Documents/Code/my_repo/周末计划生成器/xhs/example/basic_usage.py", line 31, in sign
encrypt_params = context_page.evaluate(
File "/opt/homebrew/lib/python3.9/site-packages/playwright/sync_api/_generated.py", line 8698, in evaluate
self._sync(
File "/opt/homebrew/lib/python3.9/site-packages/playwright/_impl/_sync_base.py", line 109, in _sync
return task.result()
File "/opt/homebrew/lib/python3.9/site-packages/playwright/_impl/_page.py", line 395, in evaluate
return await self._main_frame.evaluate(expression, arg)
File "/opt/homebrew/lib/python3.9/site-packages/playwright/_impl/_frame.py", line 277, in evaluate
await self._channel.send(
File "/opt/homebrew/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 61, in send
return await self._connection.wrap_api_call(
File "/opt/homebrew/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 482, in wrap_api_call
return await cb()
File "/opt/homebrew/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 97, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.Error: Execution context was destroyed, most likely because of a navigation
以下是我遇到的另外一个问题, 希望得到大佬的一些建议跟帮助
如果我管理的是一批的账号, 我发现 basic_sign_server.py 在启动之后只能为一个账号提供服务。
在启动 flask 时,通过 playwright = sync_playwright().start() ,playwright 只能被全局实例化一次。 导致这个服务只能为一个账号提供参数生成服务。
代码示例如下:
import requests
from xhs import XhsClient
def sign(uri, data=None, a1="", web_session=""):
# 填写自己的 flask 签名服务端口地址
res = requests.post("http://127.0.0.1:5006",
json={"uri": uri, "data": data, "a1": a1, "web_session": web_session})
signs = res.json()
return {
"x-s": signs["x-s"],
"x-t": signs["x-t"]
}
def run(phone, cookie):
# 实例化小红书客户端
xhs_client = XhsClient(cookie, sign=sign)
note_info = xhs_client.get_note_by_id("63db8819000000001a01ead1")
print(note_info)
if __name__ == '__main__':
cookie_1 = '''abRequestId=1; a1=18a4fb739bfi5fv56sf2afk6abyu0vzs146xvegob50000303745; webId=6cca84a5b1403b5bf6c91116bfc6cc0e; gid=yY04iDWqi8ydyY04iDWqj4dkDi32ih2KMiJ0KlDiTK0DvC2878huMh888q8qW428KiSSyd0J; webBuild=3.7.1; xsecappid=xhs-pc-web; web_session=030037a3c2c32f7f4ea717d189234a7620827d; websectiga=cffd9dcea65962b05ab048ac76962acee933d26157113bb213105a116241fa6c; sec_poison_id=c9818550-d81c-48c2-a28e-4d44a15efd38'''
cookie_2 = '''imestamp2=166892735640546fac749a852dbc5491b1bce6bf3116f372b149e46ea126eea; timestamp2.sig=e6AlCiNVwsBa0vp8V7_-NlwkR4FNCYUxm8WvibiTqxg; smidV2=202211201455567df56e0e34e99881500da7e02dd59ddc00bfe477f456168a0; gid.ss=gSMQ9UOnDuZwH2oRGJG6BW6e4grs67TaYpnrW+8Wmd3BXEQ7tNY/0XN700Ebb+IN; xhsTrackerId=73749829-fb1c-4f59-8017-f401f1ef1f95; xhsTrackerId.sig=BfS4OY4--lw8f_3iEF2V5K83Qy8bCKOeIeJG1D2-ZZw; xsecappid=xhs-pc-web; a1=186056ada1a89mvl181dbjb8arvhnl4oy26cw5vxs50000249889; webId=2b0dc450f3eea2de6a1460b70f06983c; gid=yYK82K0ffWvJyYK82K0f0J2hy0Yj6h1yYyfDKCMVDY0FhS28xI14lE888J4jYYj8fY0Y2YK2; gid.sign=IvHoU2YKjJwV3p71N5/Jc1tbZ3k=; abRequestId=2b0dc450f3eea2de6a1460b70f06983c; websectiga=10f9a40ba454a07755a08f27ef8194c53637eba4551cf9751c009d9afb564467; sec_poison_id=d4fa3381-179d-41cc-ac42-555de878e0b8; cache_feeds=[]; web_session=0400698de7e997088ffbd819c4364b0f707729; webBuild=2.11.10'''
accounts = [
{"name": "user1", "phone": "1562604xxxx", "cookie": cookie_2},
{"name": "user2", "phone": "1762973xxxx", "cookie": cookie_1},
]
for account in accounts:
name = account.get("name")
phone = account.get("phone")
cookie = account.get("cookie")
print(name, phone)
run(phone, cookie)
此时只有一个用户的执行正常。
我使用example目录下的basic_usage.py
登录小红书web版,获取cookie并复制到代码中
程序逻辑在core.py 129行self.activate
处报错,检测后发现我得cookie没有web_session字段
def cookie(self, cookie: str):
update_session_cookies_from_cookie(self.__session, cookie)
if "web_session" not in self.cookie_dict:
self.activate()
大佬你好,想问下推荐的接口和通过关键词搜索的接口多少秒请求一次才不会被封呢?
本人试图对小红书的 JavaScript 代码进行逆向,但是发现这部分的代码是混淆过的,想请教下这块是怎么分析的
想实现一个批量取关。
如题
你好,感谢项目提供的巨大帮助!
请问目前是否计划实现自动登录的流程, 用户端的操作,仅是扫二维码、收短信等, 不直接操作管理 cookie。
之前有时会显示“当前内容无法展示”,昨天更新了一下一直报错:
auth_info = xhs_client.get_user_info(line)
File "C:\python\lib\site-packages\xhs\core.py", line 315, in get_user_info
return self.get(uri, params)
File "C:\python\lib\site-packages\xhs\core.py", line 173, in get
return self.request(method="GET", url=f"{self._host}{final_uri}")
File "C:\python\lib\site-packages\xhs\core.py", line 165, in request
raise DataFetchError(data.get("msg", data))
xhs.exception.DataFetchError: {'code': -1, 'success': False}
请帮助
from xhs import XhsClient
cookie = "mycookie"
xhs_client = XhsClient(cookie, 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")
xhs_client.save_files_from_note_id("64467ef40000000013012007",
r"C:\Users\COMPUTER\Desktop\bot")
Traceback (most recent call last):
File "c:\Users\COMPUTER\Desktop\bot\tempCodeRunnerFile.python", line 4, in
xhs_client = XhsClient(cookie, 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")
File "C:\Users\COMPUTER\AppData\Local\Programs\Python\Python310\lib\site-packages\xhs\core.py", line 116, in init
self.cookie = cookie
File "C:\Users\COMPUTER\AppData\Local\Programs\Python\Python310\lib\site-packages\xhs\core.py", line 126, in cookie
self.activate()
File "C:\Users\COMPUTER\AppData\Local\Programs\Python\Python310\lib\site-packages\xhs\core.py", line 573, in activate
return self.post(uri, data={})
File "C:\Users\COMPUTER\AppData\Local\Programs\Python\Python310\lib\site-packages\xhs\core.py", line 176, in post
return self.request(method="POST", url=f"{self._host}{uri}",
File "C:\Users\COMPUTER\AppData\Local\Programs\Python\Python310\lib\site-packages\xhs\core.py", line 163, in request
raise DataFetchError(data.get("msg", None))
xhs.exception.DataFetchError: 浏览器异常,请尝试关闭/卸载风险插件或重启试试!
似乎抓取用户笔记的需求比较多,考虑通过 cli 来实现抓取,免去使用者写代码的步骤
stealth_js_path
的路径也改了,cookie也加了
我想把我关注的都爬了,但一个个分享到电脑我要死的,大概500个,大佬有没有办法破解一下,我知道我是强人锁男,就问一下😭主要我硬盘炸了,又没有备份,之前都是一个个分享到桌面端。太惨了😭
RT,大佬这是什么错误,我该如何消除
网站地址: https://creator.xiaohongshu.com/
大致发布笔记所需接口,争取这周弄出来趴
GET /api/media/v1/upload/web/permit
PUT ${fileIds}
现在内置的sign函数算出来的x-s长度和web网站的长度不一致,请求的时候一直返回 {'code': -1, 'success': False}
请问作者现在还维护吗?
Traceback (most recent call last):
File "/home/one/myhome/path/to/xhs/test.py", line 61, in
a=xhs_client.get_user_all_notes(value)
File "/home/one/.local/lib/python3.10/site-packages/xhs/core.py", line 411, in get_user_all_notes
note = self.get_note_by_id(note_id)
File "/home/one/.local/lib/python3.10/site-packages/xhs/core.py", line 190, in get_note_by_id
res = self.post(uri, data)
File "/home/one/.local/lib/python3.10/site-packages/xhs/core.py", line 178, in post
return self.request(method="POST", url=f"{self._host}{uri}",
File "/home/one/.local/lib/python3.10/site-packages/xhs/core.py", line 165, in request
raise DataFetchError(data.get("msg", data))
xhs.exception.DataFetchError: 当前内容无法展示
is_creator的作用是什么,我看都是默认的false,好像没有用过true
I used to be able to run basic_usage.py. But since yesterday, it does not work anymore. and I get
xhs.exception.DataFetchError: {'code': -1, 'success': False}
不确定是不是小红书那侧做了一些修改导致xhs不可用了
感谢大佬开发的工具,使用时遇到了一个小问题,当获取博主所有笔记时,软件获取列表会获取一部分,然后下载时会下载列表内的一部分,例如共100篇,获取时获取了70,下载时下载了50。不知道是不是共性问题,希望大佬有时间可以查看一下,附博主号“5b13f01511be104e943a48ba”、或“5a6ec20cb1da1434c660a82d”
获取笔记数据时,获取几十条就会出现频率限制
Traceback (most recent call last): File "/home/python3.9/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app response = self.full_dispatch_request() File "/home/python3.9/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/python3.9/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request rv = self.dispatch_request() File "/home/python3.9/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) File "/www/wwwroot/xhs_python/app.py", line 27, in xhs client = XhsClient(cookie) File "/home/python3.9/lib/python3.9/site-packages/xhs/core.py", line 114, in __init__ self.cookie = cookie File "/home/python3.9/lib/python3.9/site-packages/xhs/core.py", line 124, in cookie self.activate() File "/home/python3.9/lib/python3.9/site-packages/xhs/core.py", line 568, in activate return self.post(uri, data={}) File "/home/python3.9/lib/python3.9/site-packages/xhs/core.py", line 171, in post return self.request(method="POST", url=f"{self._host}{uri}", File "/home/python3.9/lib/python3.9/site-packages/xhs/core.py", line 156, in request raise IPBlockError(self.IP_ERROR_STR) xhs.exception.IPBlockError: 网络连接异常,请检查网络设置或重启试试
我试了几个不同的笔记好像都是这样,请问别人有同样的问题吗?
按照文档执行如下代码,提示“无登录信息,或登录信息为空”
from xhs import XhsClient
// cookie在网页https://www.xiaohongshu.com/user/profile/用户ID
// 执行js代码:console.log(document.cookie); 得到,
cookie = "请从网页端获取你的 cookie"
xhs_client = XhsClient(cookie)
result = xhs_client.get_user_notes("用户ID")
print(result)
执行效果如图:
请问如何能正常使用,谢谢🙏
{'code': 300015, 'success': False, 'msg': '浏览器异常,请尝试关闭/卸载风险插件或重启试试'}
不知道是不是和验证码有关系,有时间看一看
我这边用模拟浏览器(playwright)完成了小红书X-s参数的获取,感兴趣可以看下,https://github.com/NanmiCoder/MediaCrawler
最初由 NanmiCoder 在 #13 (comment) 发布
使用的是python3.9
一开始还以为是我cookie的问题,换了好几次cookie还是报错
from xhs import XhsClient
cookie="a1=1886132f6cav7mfdpcid2mnbahv45uuvea5z3lvji30000329042;webId=b360cce06e1bcad5e48dafb7b612265e;gid=yYYKyqJiYydqyYYKyqJiK01hS0hW6ifUS3fJ2V36ID0xhuq84277hq888qJj84J8ji8dW2S0;gid.sign=3gVA5Ji2C13wAa8svTrYyqcJDc8=;webBuild=2.11.5;acw_tc=0ab967f98018c20dd6b0745ee8a1596c3750bf84d2f8727a93f5c10315054162; web_session=040069b253793fdd9ccd5842a2364b86586515;galaxy_creator_session_id=S5mv0vWIWqrCX2GSJK9LFaudFrUkNq7TYW3b;galaxy.creator.beaker.session.id=1687620188771003075230;xsecappid=creator-creator;websectiga=2a3d3ea002e7d92b5c9743590ebd24010cf3710ff3af8029153751e41a6af4a3;sec_poison_id=f93e48b6-3162-4f6f-9984-5fcd908695cb"
xhs_client=XhsClient(cookie)
# xhs_client.get_home_feed(xhs.FeedType.RECOMMEND)
xhs_client.get_note_by_id("63db8819000000001a01ead1")
Traceback (most recent call last):
File "/Users/cyc/Desktop/小红书素材/run.py", line 6, in <module>
xhs_client.get_note_by_id("63db8819000000001a01ead1")
File "/usr/local/lib/python3.9/site-packages/xhs/core.py", line 190, in get_note_by_id
res = self.post(uri, data)
File "/usr/local/lib/python3.9/site-packages/xhs/core.py", line 176, in post
self._pre_headers(uri, data, is_creator=is_creator)
File "/usr/local/lib/python3.9/site-packages/xhs/core.py", line 148, in _pre_headers
self.sign(url, data, a1=self.cookie_dict.get("a1"),
TypeError: 'NoneType' object is not callable
辛苦回复一下 感谢🙏🏻
123
I installed the latest version: 0.1.9.
When I try to download files by note id, xhs client will exit with exception:
XhsClient' object has no attribute '_get_img_urls_from_note
I searched from source code, class XhsClient has no protect function _get_video_url_from_note
and _get_img_urls_from_note
Should I intall any other requirements?
如题
情况:当一个博主笔记量太多了,有几百个,但是只有最新的几十个比较有用,是否可以设置限制爬取的笔记个数呢
能不能出个发布图文笔记的接口啊 万分感谢
通过cookie获取笔记详情的功能失效了 大佬辛苦修复下!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.