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)
- 请问basic_usage.py中如何进行分页搜索获取结果 HOT 2
- 请问能否支持大文件分片上传 HOT 7
- 搜索笔记接口get_note_by_keyword有数量限制 HOT 2
- Docker 容器架构 The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64/v2) and no specific platform was requested HOT 1
- 请问xhsClient初始化 proxies传入格式有示例么 HOT 1
- 请问有抖音版的吗 HOT 1
- 请求结果报错:xhs.exception.DataFetchError: {'code': -1, 'success': False} HOT 2
- 发布接口报错:无登录信息 HOT 9
- 在文章中@别人,别人收不到信息,但是评论里能点开别人的信息 HOT 1
- 发布笔记接口,topics好像无效 HOT 4
- 请问有 私信接口吗 HOT 1
- 签名函数不一定能 work
- 关注用户,用户好像不能收到通知 HOT 1
- 如何监控被用户评论区@的消息 HOT 8
- feat: 将`xhs`封装为tools供ChatGPT调用
- 好像login_qrcode的二维码扫不出 HOT 1
- 浏览器打开后部分接口报406 HOT 1
- 请问有获取粉丝id的接口吗?想做一个批量取关的功能 HOT 2
- 测试方法test_create_note_with_ats_topics中at他人时的name与nickname是一样的吗? HOT 2
- 现在请求两三次就抓不到数据了,怎么办 HOT 2
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.