1. add stealth to avoid detect
This commit is contained in:
@@ -167,3 +167,4 @@ youtube_uploader/*.json
|
||||
douyin_uploader/*.json
|
||||
bilibili_uploader/*.json
|
||||
tk_uploader/*.json
|
||||
cookies
|
||||
@@ -196,7 +196,7 @@ xhs签名方式分为两种:
|
||||
故如果你有多账号分发,建议采用自建签名服务(todo 上传docker配置)
|
||||
```
|
||||
##### 疑难杂症
|
||||
遇到签名问题,可尝试更新cdn.jsdelivr.net_gh_requireCool_stealth.min.js_stealth.min.js文件
|
||||
遇到签名问题,可尝试更新 "utils/stealth.min.js"文件
|
||||
https://github.com/requireCool/stealth.min.js
|
||||
|
||||
24.4.10 大多数人小红书失败的原因在于你的cookie有问题,请参照你cookie是不是如我这样
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pathlib
|
||||
from datetime import datetime
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
@@ -7,12 +6,14 @@ import os
|
||||
import asyncio
|
||||
|
||||
from conf import LOCAL_CHROME_PATH
|
||||
from utils.base_social_media import set_init_script
|
||||
|
||||
|
||||
async def cookie_auth(account_file):
|
||||
async with async_playwright() as playwright:
|
||||
browser = await playwright.chromium.launch(headless=True)
|
||||
context = await browser.new_context(storage_state=account_file)
|
||||
context = await set_init_script(context)
|
||||
# 创建一个新的页面
|
||||
page = await context.new_page()
|
||||
# 访问指定的 URL
|
||||
@@ -45,6 +46,7 @@ async def douyin_cookie_gen(account_file):
|
||||
browser = await playwright.chromium.launch(**options)
|
||||
# Setup context however you like.
|
||||
context = await browser.new_context() # Pass any options
|
||||
context = await set_init_script(context)
|
||||
# Pause the page, and start recording manually.
|
||||
page = await context.new_page()
|
||||
await page.goto("https://creator.douyin.com/")
|
||||
@@ -91,6 +93,7 @@ class DouYinVideo(object):
|
||||
browser = await playwright.chromium.launch(headless=False)
|
||||
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
||||
context = await browser.new_context(storage_state=f"{self.account_file}")
|
||||
context = await set_init_script(context)
|
||||
|
||||
# 创建一个新的页面
|
||||
page = await context.new_page()
|
||||
|
||||
+21
-16
@@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
@@ -7,6 +6,7 @@ import os
|
||||
import asyncio
|
||||
|
||||
from conf import LOCAL_CHROME_PATH
|
||||
from utils.base_social_media import set_init_script
|
||||
from utils.files_times import get_absolute_path
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ async def cookie_auth(account_file):
|
||||
async with async_playwright() as playwright:
|
||||
browser = await playwright.chromium.launch(headless=True)
|
||||
context = await browser.new_context(storage_state=account_file)
|
||||
context = await set_init_script(context)
|
||||
# 创建一个新的页面
|
||||
page = await context.new_page()
|
||||
# 访问指定的 URL
|
||||
@@ -47,20 +48,25 @@ async def cookie_auth(account_file):
|
||||
return True
|
||||
|
||||
|
||||
async def save_storage_state(account_file: str):
|
||||
async with async_playwright() as p:
|
||||
browser = await p.chromium.launch(headless=False)
|
||||
context = await browser.new_context()
|
||||
async def get_tencent_cookie(account_file):
|
||||
async with async_playwright() as playwright:
|
||||
options = {
|
||||
'args': [
|
||||
'--lang en-GB'
|
||||
],
|
||||
'headless': False, # Set headless option here
|
||||
}
|
||||
# Make sure to run headed.
|
||||
browser = await playwright.chromium.launch(**options)
|
||||
# Setup context however you like.
|
||||
context = await browser.new_context() # Pass any options
|
||||
# Pause the page, and start recording manually.
|
||||
context = await set_init_script(context)
|
||||
page = await context.new_page()
|
||||
await page.goto("https://channels.weixin.qq.com")
|
||||
print("请在浏览器中扫码登录...")
|
||||
await asyncio.sleep(20) # 给用户60秒时间进行扫码登录
|
||||
|
||||
# 保存存储状态到文件
|
||||
storage_state = await context.storage_state()
|
||||
with open(account_file, 'w') as f:
|
||||
f.write(json.dumps(storage_state))
|
||||
await browser.close()
|
||||
await page.pause()
|
||||
# 点击调试器的继续,保存cookie
|
||||
await context.storage_state(path=account_file)
|
||||
|
||||
|
||||
async def weixin_setup(account_file, handle=False):
|
||||
@@ -70,9 +76,7 @@ async def weixin_setup(account_file, handle=False):
|
||||
# Todo alert message
|
||||
return False
|
||||
print('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
|
||||
# await save_storage_state(account_file)
|
||||
os.system('python3 -m playwright install')
|
||||
os.system(f'playwright codegen channels.weixin.qq.com --save-storage={account_file}') # 生成cookie文件
|
||||
await get_tencent_cookie(account_file)
|
||||
return True
|
||||
|
||||
|
||||
@@ -135,6 +139,7 @@ class TencentVideo(object):
|
||||
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
|
||||
# 创建一个浏览器上下文,使用指定的 cookie 文件
|
||||
context = await browser.new_context(storage_state=f"{self.account_file}")
|
||||
context = await set_init_script(context)
|
||||
|
||||
# 创建一个新的页面
|
||||
page = await context.new_page()
|
||||
|
||||
+4
-2
@@ -3,10 +3,10 @@ import re
|
||||
from datetime import datetime
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
import time
|
||||
import os
|
||||
import asyncio
|
||||
from tk_uploader.tk_config import Tk_Locator
|
||||
from utils.base_social_media import set_init_script
|
||||
from utils.files_times import get_absolute_path
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ async def cookie_auth(account_file):
|
||||
async with async_playwright() as playwright:
|
||||
browser = await playwright.firefox.launch(headless=True)
|
||||
context = await browser.new_context(storage_state=account_file)
|
||||
context = await set_init_script(context)
|
||||
# 创建一个新的页面
|
||||
page = await context.new_page()
|
||||
# 访问指定的 URL
|
||||
@@ -57,6 +58,7 @@ async def get_tiktok_cookie(account_file):
|
||||
browser = await playwright.firefox.launch(**options)
|
||||
# Setup context however you like.
|
||||
context = await browser.new_context() # Pass any options
|
||||
context = await set_init_script(context)
|
||||
# Pause the page, and start recording manually.
|
||||
page = await context.new_page()
|
||||
await page.goto("https://www.tiktok.com/creator-center/content")
|
||||
@@ -138,7 +140,7 @@ class TiktokVideo(object):
|
||||
async def upload(self, playwright: Playwright) -> None:
|
||||
browser = await playwright.firefox.launch(headless=False)
|
||||
context = await browser.new_context(storage_state=f"{self.account_file}")
|
||||
|
||||
context = await set_init_script(context)
|
||||
page = await context.new_page()
|
||||
|
||||
await page.goto("https://www.tiktok.com/creator-center/upload")
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from conf import BASE_DIR
|
||||
|
||||
SOCIAL_MEDIA_DOUYIN = "douyin"
|
||||
SOCIAL_MEDIA_TENCENT = "tencent"
|
||||
SOCIAL_MEDIA_TIKTOK = "tiktok"
|
||||
@@ -12,3 +15,9 @@ def get_supported_social_media() -> List[str]:
|
||||
|
||||
def get_cli_action() -> List[str]:
|
||||
return ["upload", "login", "watch"]
|
||||
|
||||
|
||||
async def set_init_script(context):
|
||||
stealth_js_path = Path(BASE_DIR / "utils/stealth.min.js")
|
||||
await context.add_init_script(path=stealth_js_path)
|
||||
return context
|
||||
|
||||
Vendored
+7
File diff suppressed because one or more lines are too long
@@ -16,8 +16,7 @@ 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) / "xhs_uploader" / "cdn.jsdelivr.net_gh_requireCool_stealth.min.js_stealth.min.js"
|
||||
stealth_js_path = pathlib.Path(BASE_DIR / "utils/stealth.min.js")
|
||||
chromium = playwright.chromium
|
||||
|
||||
# 如果一直失败可尝试设置成 False 让其打开浏览器,适当添加 sleep 可查看浏览器状态
|
||||
|
||||
Reference in New Issue
Block a user