Track bundled vendor runtime sources
This commit is contained in:
0
vendor/social-auto-upload/uploader/xhs_uploader/__init__.py
vendored
Normal file
0
vendor/social-auto-upload/uploader/xhs_uploader/__init__.py
vendored
Normal file
58
vendor/social-auto-upload/uploader/xhs_uploader/main.py
vendored
Normal file
58
vendor/social-auto-upload/uploader/xhs_uploader/main.py
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import configparser
|
||||
import json
|
||||
import pathlib
|
||||
from time import sleep
|
||||
|
||||
import requests
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
from conf import BASE_DIR, XHS_SERVER, LOCAL_CHROME_HEADLESS
|
||||
|
||||
config = configparser.RawConfigParser()
|
||||
config.read('accounts.ini')
|
||||
|
||||
|
||||
def sign_local(uri, data=None, a1="", web_session=""):
|
||||
for _ in range(10):
|
||||
try:
|
||||
with sync_playwright() as playwright:
|
||||
stealth_js_path = pathlib.Path(BASE_DIR / "utils/stealth.min.js")
|
||||
chromium = playwright.chromium
|
||||
|
||||
# 如果一直失败可尝试设置成 False 让其打开浏览器,适当添加 sleep 可查看浏览器状态
|
||||
browser = chromium.launch(headless=LOCAL_CHROME_HEADLESS)
|
||||
|
||||
browser_context = browser.new_context()
|
||||
browser_context.add_init_script(path=stealth_js_path)
|
||||
context_page = browser_context.new_page()
|
||||
context_page.goto("https://www.xiaohongshu.com")
|
||||
browser_context.add_cookies([
|
||||
{'name': 'a1', 'value': a1, 'domain': ".xiaohongshu.com", 'path': "/"}]
|
||||
)
|
||||
context_page.reload()
|
||||
# 这个地方设置完浏览器 cookie 之后,如果这儿不 sleep 一下签名获取就失败了,如果经常失败请设置长一点试试
|
||||
sleep(2)
|
||||
encrypt_params = context_page.evaluate("([url, data]) => window._webmsxyw(url, data)", [uri, data])
|
||||
return {
|
||||
"x-s": encrypt_params["X-s"],
|
||||
"x-t": str(encrypt_params["X-t"])
|
||||
}
|
||||
except Exception:
|
||||
# 这儿有时会出现 window._webmsxyw is not a function 或未知跳转错误,因此加一个失败重试趴
|
||||
pass
|
||||
raise Exception("重试了这么多次还是无法签名成功,寄寄寄")
|
||||
|
||||
|
||||
def sign(uri, data=None, a1="", web_session=""):
|
||||
# 填写自己的 flask 签名服务端口地址
|
||||
res = requests.post(f"{XHS_SERVER}/sign",
|
||||
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 beauty_print(data: dict):
|
||||
print(json.dumps(data, ensure_ascii=False, indent=2))
|
||||
34
vendor/social-auto-upload/uploader/xhs_uploader/xhs_login_qrcode.py
vendored
Normal file
34
vendor/social-auto-upload/uploader/xhs_uploader/xhs_login_qrcode.py
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import datetime
|
||||
import json
|
||||
import qrcode
|
||||
from time import sleep
|
||||
|
||||
from xhs import XhsClient
|
||||
|
||||
from uploader.xhs_uploader.main import sign
|
||||
|
||||
# pip install qrcode
|
||||
if __name__ == '__main__':
|
||||
xhs_client = XhsClient(sign=sign, timeout=60)
|
||||
print(datetime.datetime.now())
|
||||
qr_res = xhs_client.get_qrcode()
|
||||
qr_id = qr_res["qr_id"]
|
||||
qr_code = qr_res["code"]
|
||||
|
||||
qr = qrcode.QRCode(version=1, error_correction=qrcode.ERROR_CORRECT_L,
|
||||
box_size=50,
|
||||
border=1)
|
||||
qr.add_data(qr_res["url"])
|
||||
qr.make()
|
||||
qr.print_ascii()
|
||||
|
||||
while True:
|
||||
check_qrcode = xhs_client.check_qrcode(qr_id, qr_code)
|
||||
print(check_qrcode)
|
||||
sleep(1)
|
||||
if check_qrcode["code_status"] == 2:
|
||||
print(json.dumps(check_qrcode["login_info"], indent=4))
|
||||
print("当前 cookie:" + xhs_client.cookie)
|
||||
break
|
||||
|
||||
print(json.dumps(xhs_client.get_self_info(), indent=4))
|
||||
Reference in New Issue
Block a user