Comments (4)
不太理解你需要的自动登录流程是怎样的?
我理解的只能是半自动化的:
- 扫码,打印二维码,等待用户扫描成功,自动保存 cookie 后结束登录操作。
- 短信登录,发送短信,等待用户输入短信验证码,自动保存 cookie 后结束登录操作。
你的意思是 XhsClient 初始化默认不传入 cookie,然后根据登录操作来进行获取 cookie 和保存会话的操作吗?
from xhs.
是这样的, 半自动化。
请问下面的两个流程现在有实现吗:
(1) 扫码,打印二维码,等待用户扫描成功,自动保存 cookie 后结束登录操作。
(2) 短信登录,发送短信,等待用户输入短信验证码,自动保存 cookie 后结束登录操作。
我找到了与二维码登录相关的两个封装接口:
get_qrcode 以及 check_qrcode
举例, 在 get_qrcode 接口返回:
{'code': 0, 'data': {'code': '764989', 'multi_flag': 0, 'qr_id': '532531693549495862', 'url': 'xhsdiscover://rn/app-settings/login/scan?qrId=532531693549495862&ruleId=4&code=764989×tamp=1693549495876'}, 'msg': '成功', 'success': True}
用其参数输入 check_qrcode 返回:
{'code_status': 0}
这个流程我不是很清晰怎么获取到二维码图片以及在扫描后保存到 cookie
from xhs.
即不希望输入是 cookie,这样对于非技术人员他们可能不是很理解这个参数第一次从哪里获取。
希望能有一个自动化或者半自动化获取 cookie 的封装。
from xhs.
import os
import time
import loguru
from playwright.sync_api import Playwright, sync_playwright, expect
logger = loguru.logger
cur_project = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
logger.info(f"cur_project: {cur_project}")
stealth_js_path = os.path.join(cur_project, 'js', "stealth.min.js")
def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
context = browser.new_context(
viewport={"width": 1920, "height": 1080},
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 "
"Safari/537.36"
)
context.add_cookies([
{'name': 'webId', 'value': "1", 'domain': ".xiaohongshu.com", 'path': "/"}
])
context.add_init_script(path=stealth_js_path)
page = context.new_page()
page.goto("https://www.xiaohongshu.com/explore")
time.sleep(10)
page.get_by_placeholder("输入手机号").click()
page.get_by_placeholder("输入手机号").fill("1562604xxxx")
page.locator(".agree-icon > .reds-icon").click()
page.get_by_text("获取验证码").click()
code = input(f"请输入你收到的验证码:").strip()
logger.warning(f"收到验证码{code}")
page.get_by_placeholder("输入验证码").fill(code)
time.sleep(10)
page.get_by_role("button", name="登录").first.click()
page.goto("https://www.xiaohongshu.com/explore")
logger.warning(context.cookies())
time.sleep(10)
page.close()
# ---------------------
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)
目前我通过此脚本为第一次生成 cookie
from xhs.
Related Issues (20)
- docker中崩溃 HOT 9
- 出现requests.exceptions.ConnectionError HOT 2
- 笔记发布接口提示TypeError
- 请求发布图片笔记接口报406 HOT 1
- ubuntu22.04版本的openssl3.0出现这个问题
- get_note_by_id 返回461错误 HOT 1
- 获取话题的发布问题 HOT 2
- [get_note_by_id] 现在总是 return {} HOT 14
- report_note_metrics方法时好时坏 HOT 1
- 获取笔记评论 提示 超时 HOT 3
- 有获取创作者cookie的api吗 HOT 3
- 可以支持回复私信的功能吗? HOT 6
- 为什么这里可以不传 a1 参数 HOT 1
- xhs 发布图文提示“技术升级中”,请教这是什么原因导致的呢?
- 刚注册的新号,调用二维码接口获取到二维码之后,手机上扫码成功,但是获取二维码扫描状态的接口 返回 461 或者 471 ,怎么解决。。。
- 赞 成功了,对面收不到,这种这么办?
- 发送短信出现错误 HOT 4
- 在mac,m1上,不行🙅 HOT 2
- 视频发布有文件大小限制吗? HOT 2
- 获取笔记信息的时候报错 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xhs.