Toggle navigation
Toggle navigation
This project
Loading...
Sign in
LiuFuhua
/
xj-marketing
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
rinalLi
2024-12-24 17:16:39 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
8d267b3ebe2a5fb21ce4eeb2aeae625fcf78044a
8d267b3e
2 parents
0df95779
cc763b39
Merge branch 'master' of
ssh://gitlab.rinal-li.cn:10022/liufuhua/xj-marketing
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
195 additions
and
88 deletions
cli_main.py
uploader/bjh_uploader/main.py
uploader/douyin_uploader/main.py
uploader/ks_uploader/main.py
uploader/tencent_uploader/main.py
uploader/toutiao_uploader/main.py
uploader/wyh_uploader/main.py
utils/base_social_media.py
cli_main.py
View file @
8d267b3
...
...
@@ -74,12 +74,37 @@ async def main():
elif
args
.
platform
==
SOCIAL_MEDIA_KUAISHOU
:
await
ks_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_WANGYIHAO
:
await
wyh_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
False
)
# elif args.platform == SOCIAL_MEDIA_XHS:
# await xhs_setup(str(account_file), handle=True)
await
wyh_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_XHS
:
await
xhs_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_TOUTIAO
:
await
toutiao_setup
(
str
(
account_file
),
handle
=
True
)
await
toutiao_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
False
)
elif
args
.
platform
==
SOCIAL_MEDIA_BAIJIAHAO
:
await
toutiao_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
False
)
elif
args
.
platform
==
SOCIAL_MEDIA_SOHU
:
await
sohu_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
action
==
'auto_login'
:
print
(
f
"auto Logging in with account {args.account_name} on platform {args.platform}"
)
if
args
.
platform
==
SOCIAL_MEDIA_DOUYIN
:
await
douyin_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_TIKTOK
:
await
tiktok_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_TENCENT
:
await
weixin_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_KUAISHOU
:
await
ks_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_WANGYIHAO
:
await
wyh_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
True
)
# elif args.platform == SOCIAL_MEDIA_XHS:
# await xhs_setup(str(account_file), handle=True)
elif
args
.
platform
==
SOCIAL_MEDIA_TOUTIAO
:
await
toutiao_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_BAIJIAHAO
:
await
toutiao_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
True
)
await
toutiao_setup
(
str
(
account_file
),
handle
=
True
)
elif
args
.
platform
==
SOCIAL_MEDIA_SOHU
:
await
sohu_setup
(
str
(
account_file
),
handle
=
True
)
...
...
uploader/bjh_uploader/main.py
View file @
8d267b3
...
...
@@ -6,20 +6,20 @@ from utils.log import kuaishou_logger
from
playwright.async_api
import
Playwright
,
async_playwright
async
def
wy
h_setup
(
account_file
,
handle
=
False
):
async
def
bj
h_setup
(
account_file
,
handle
=
False
):
print
(
account_file
)
account_file
=
get_absolute_path
(
account_file
,
"wyh_uploader"
)
if
not
os
.
path
.
exists
(
account_file
):
if
not
handle
:
return
False
kuaishou_logger
.
info
(
'[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件'
)
await
get_
wy
h_cookie
(
account_file
)
await
get_
bj
h_cookie
(
account_file
)
else
:
await
open_
wy
h_main_page
(
account_file
)
await
open_
bj
h_main_page
(
account_file
)
return
True
async
def
open_
wy
h_main_page
(
account_file
):
async
def
open_
bj
h_main_page
(
account_file
):
async
with
async_playwright
()
as
playwright
:
options
=
{
'args'
:
[
...
...
@@ -55,7 +55,7 @@ async def open_wyh_main_page(account_file):
browser
.
close
()
async
def
get_
wy
h_cookie
(
account_file
):
async
def
get_
bj
h_cookie
(
account_file
):
print
(
"get_wyh_cookie"
)
async
with
async_playwright
()
as
playwright
:
options
=
{
...
...
@@ -77,6 +77,12 @@ async def get_wyh_cookie(account_file):
# await context.storage_state(path=account_file)
# 自动登陆
await
page
.
wait_for_timeout
(
2000
0
)
await
page
.
wait_for_timeout
(
2000
)
await
page
.
get_by_text
(
'注册/登录百家号'
)
.
click
()
await
page
.
pause
()
await
page
.
wait_for_timeout
(
2000
)
await
page
.
locator
(
"//*[@class='pass-text-input pass-text-input-userName']"
)
.
fill
(
"idiotbc"
)
await
page
.
wait_for_timeout
(
2000
)
await
page
.
locator
(
"//*[@class='pass-text-input pass-text-input-password']"
)
.
fill
(
"Liuyihong1023@"
)
await
page
.
wait_for_timeout
(
2000
)
await
page
.
locator
(
"//*[@class='pass-checkbox-input pass-checkbox-isAgree']"
)
.
click
()
await
page
.
wait_for_timeout
(
2000
)
...
...
uploader/douyin_uploader/main.py
View file @
8d267b3
...
...
@@ -99,10 +99,11 @@ class DouYinVideo(object):
async
def
upload
(
self
,
playwright
:
Playwright
)
->
None
:
# 使用 Chromium 浏览器启动一个浏览器实例
if
self
.
local_executable_path
:
browser
=
await
playwright
.
chromium
.
launch
(
headless
=
False
,
executable_path
=
self
.
local_executable_path
)
else
:
browser
=
await
playwright
.
chromium
.
launch
(
headless
=
False
)
# if self.local_executable_path:
# browser = await playwright.chromium.launch(headless=True, executable_path=self.local_executable_path)
# else:
print
(
"test"
)
browser
=
await
playwright
.
chromium
.
launch
()
# 创建一个浏览器上下文,使用指定的 cookie 文件
context
=
await
browser
.
new_context
(
storage_state
=
f
"{self.account_file}"
)
context
=
await
set_init_script
(
context
)
...
...
uploader/ks_uploader/main.py
View file @
8d267b3
...
...
@@ -83,14 +83,14 @@ class KSVideo(object):
async
def
upload
(
self
,
playwright
:
Playwright
)
->
None
:
# 使用 Chromium 浏览器启动一个浏览器实例
print
(
self
.
local_executable_path
)
if
self
.
local_executable_path
:
browser
=
await
playwright
.
chromium
.
launch
(
headless
=
Fals
e
,
executable_path
=
self
.
local_executable_path
,
)
else
:
browser
=
await
playwright
.
chromium
.
launch
(
headless
=
Fals
e
#
if self.local_executable_path:
#
browser = await playwright.chromium.launch(
# headless=Tru
e,
#
executable_path=self.local_executable_path,
#
)
#
else:
browser
=
await
playwright
.
firefox
.
launch
(
headless
=
Tru
e
)
# 创建一个浏览器上下文,使用指定的 cookie 文件
context
=
await
browser
.
new_context
(
storage_state
=
f
"{self.account_file}"
)
context
=
await
set_init_script
(
context
)
...
...
@@ -104,19 +104,48 @@ class KSVideo(object):
# 等待页面跳转到指定的 URL,没进入,则自动等待到超时
kuaishou_logger
.
info
(
'正在打开主页...'
)
await
page
.
wait_for_url
(
"https://cp.kuaishou.com/article/publish/video"
)
# 点击 "上传视频" 按钮
upload_button
=
page
.
locator
(
"button[class^='_upload-btn']"
)
await
upload_button
.
wait_for
(
state
=
'visible'
)
# 确保按钮可见
async
with
page
.
expect_file_chooser
()
as
fc_info
:
await
upload_button
.
click
()
file_chooser
=
await
fc_info
.
value
await
file_chooser
.
set_files
(
self
.
file_path
)
await
asyncio
.
sleep
(
2
)
# # 点击 "上传视频" 按钮
# upload_button = page.locator("button[class^='_upload-btn']")
# await upload_button.wait_for(state='visible') # 确保按钮可见
#
# async with page.expect_file_chooser() as fc_info:
# await upload_button.click()
# file_chooser = await fc_info.value
# await file_chooser.set_files(self.file_path)
await
page
.
locator
(
"div[class^='_publish-container'] input"
)
.
set_input_files
(
self
.
file_path
)
await
asyncio
.
sleep
(
5
)
# 判断视频是否上传成功,去除引导页
while
True
:
# 判断视频是否上传成功,去除引导页
try
:
skip_button
=
page
.
get_by_role
(
'button'
,
name
=
"Skip"
,
exact
=
True
)
if
await
skip_button
.
count
():
await
skip_button
.
click
()
await
asyncio
.
sleep
(
1
)
else
:
await
asyncio
.
sleep
(
1
)
break
except
:
kuaishou_logger
.
info
(
" [-] 视频正在发布中..."
)
await
asyncio
.
sleep
(
0.5
)
break
# if not await page.get_by_text("封面编辑").count():
# raise Exception("似乎没有跳转到到编辑页面")
if
not
await
page
.
get_by_text
(
"封面设置"
)
.
count
():
raise
Exception
(
"似乎没有跳转到到编辑页面"
)
# 等待页面跳转到指定的 URL
# while True:
# # 判断是是否进入视频发布页面,没进入,则自动等待到超时
# try:
# await page.locator('//html/body/div').wait_for(state="attached")
# break
# except:
# kuaishou_logger.info(f' [-] 正在等待进入视频发布页面...')
# await asyncio.sleep(0.1)
# # if not await page.get_by_text("作品描述").count():
# # raise Exception("似乎没有跳转到到编辑页面")
await
asyncio
.
sleep
(
1
)
...
...
uploader/tencent_uploader/main.py
View file @
8d267b3
...
...
@@ -137,7 +137,9 @@ class TencentVideo(object):
async
def
upload
(
self
,
playwright
:
Playwright
)
->
None
:
# 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误
browser
=
await
playwright
.
chromium
.
launch
(
headless
=
False
,
executable_path
=
self
.
local_executable_path
)
# browser = await playwright.chromium.launch(headless=True, executable_path=self.local_executable_path)
browser
=
await
playwright
.
firefox
.
launch
(
headless
=
True
)
# 创建一个浏览器上下文,使用指定的 cookie 文件
context
=
await
browser
.
new_context
(
storage_state
=
f
"{self.account_file}"
)
context
=
await
set_init_script
(
context
)
...
...
@@ -150,8 +152,9 @@ class TencentVideo(object):
# 等待页面跳转到指定的 URL,没进入,则自动等待到超时
await
page
.
wait_for_url
(
"https://channels.weixin.qq.com/platform/post/create"
)
# await page.wait_for_selector('input[type="file"]', timeout=10000)
file_input
=
page
.
locator
(
'input[type="file"]'
)
await
file_input
.
set_input_files
(
self
.
file_path
)
file_input
=
await
page
.
locator
(
'input[type="file"]'
)
.
set_input_files
(
self
.
file_path
)
await
page
.
wait_for_selector
(
".cover-img-horizontal"
,
state
=
"attached"
)
# await file_input.set_input_files(self.file_path)
# 填充标题和话题
await
self
.
add_title_tags
(
page
)
# 添加商品
...
...
uploader/toutiao_uploader/main.py
View file @
8d267b3
...
...
@@ -6,25 +6,25 @@ from utils.log import kuaishou_logger
from
playwright.async_api
import
Playwright
,
async_playwright
async
def
toutiao_setup
(
account_file
,
handle
=
False
):
async
def
toutiao_setup
(
account_file
,
handle
=
False
,
auto
=
False
):
print
(
account_file
)
account_file
=
get_absolute_path
(
account_file
,
"wyh_uploader"
)
if
not
os
.
path
.
exists
(
account_file
):
if
not
handle
:
return
False
kuaishou_logger
.
info
(
'[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件'
)
await
get_wyh_cookie
(
account_file
)
if
not
auto
:
await
get_toutiao_cookie
(
account_file
)
else
:
await
open_wyh_main_page
(
account_file
)
await
get_toutiao_cookie_auto
(
account_file
)
else
:
await
open_toutiao_main_page
(
account_file
)
return
True
async
def
open_
wyh
_main_page
(
account_file
):
async
def
open_
toutiao
_main_page
(
account_file
):
async
with
async_playwright
()
as
playwright
:
options
=
{
'args'
:
[
'--lang en-GB'
],
'headless'
:
False
,
# Set headless option here
}
# Make sure to run headed.
...
...
@@ -39,8 +39,8 @@ async def open_wyh_main_page(account_file):
browser
.
close
()
async
def
get_
wyh_cookie
(
account_file
):
print
(
"get_
wyh
_cookie"
)
async
def
get_
toutiao_cookie_auto
(
account_file
):
print
(
"get_
toutiao
_cookie"
)
async
with
async_playwright
()
as
playwright
:
options
=
{
'args'
:
[
...
...
@@ -57,24 +57,41 @@ async def get_wyh_cookie(account_file):
page
=
await
context
.
new_page
()
await
page
.
goto
(
"https://mp.toutiao.com"
)
# 手动授权登录
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
# 自动登陆
await
page
.
wait_for_timeout
(
5
000
)
await
page
.
wait_for_timeout
(
2
000
)
await
page
.
get_by_text
(
'密码登录'
)
.
click
()
await
page
.
wait_for_timeout
(
5
000
)
await
page
.
wait_for_timeout
(
2
000
)
await
page
.
get_by_placeholder
(
"手机号/邮箱"
)
.
fill
(
'18610534668'
)
print
(
"输入账号成功"
)
await
page
.
wait_for_timeout
(
1000
)
await
page
.
get_by_placeholder
(
'密码'
)
.
fill
(
"Liuyihong1023@"
)
await
page
.
wait_for_timeout
(
1
000
)
await
page
.
wait_for_timeout
(
2
000
)
await
page
.
locator
(
"//*[@class='web-login-confirm-info__checkbox']"
)
.
click
()
await
page
.
wait_for_timeout
(
1
000
)
await
page
.
wait_for_timeout
(
2
000
)
await
page
.
locator
(
"//*[@class='web-login-button']"
)
.
click
()
await
page
.
wait_for_timeout
(
10000
)
await
page
.
wait_for_timeout
(
2000
)
# 点击调试器的继续,保存cookie
await
context
.
storage_state
(
path
=
account_file
)
async
def
get_toutiao_cookie
(
account_file
):
print
(
"get_toutiao_cookie"
)
async
with
async_playwright
()
as
playwright
:
options
=
{
'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
context
=
await
set_init_script
(
context
)
# Pause the page, and start recording manually.
page
=
await
context
.
new_page
()
await
page
.
goto
(
"https://mp.toutiao.com"
,
{
waitUntil
:
"commit"
})
# 手动授权登录
await
page
.
pause
()
# 点击调试器的继续,保存cookie
await
context
.
storage_state
(
path
=
account_file
)
...
...
uploader/wyh_uploader/main.py
View file @
8d267b3
...
...
@@ -6,20 +6,26 @@ from utils.log import kuaishou_logger
from
playwright.async_api
import
Playwright
,
async_playwright
async
def
wyh_setup
(
account_file
,
handle
=
False
):
async
def
wyh_setup
(
account_file
,
handle
=
False
,
auto
=
False
):
print
(
account_file
)
account_file
=
get_absolute_path
(
account_file
,
"wyh_uploader"
)
if
not
os
.
path
.
exists
(
account_file
):
if
not
handle
:
return
False
kuaishou_logger
.
info
(
'[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件'
)
if
not
auto
:
await
get_wyh_cookie
(
account_file
)
else
:
await
get_wyh_cookie_auto
(
account_file
)
else
:
await
open_wyh_main_page
(
account_file
)
return
True
async
def
open_wyh_main_page
(
account_file
):
'''
'''
async
def
get_wyh_cookie_auto
(
account_file
):
print
(
"get_wyh_cookie"
)
async
with
async_playwright
()
as
playwright
:
options
=
{
'args'
:
[
...
...
@@ -30,33 +36,29 @@ async def open_wyh_main_page(account_file):
# Make sure to run headed.
browser
=
await
playwright
.
chromium
.
launch
(
**
options
)
# Setup context however you like.
context
=
await
browser
.
new_context
(
storage_state
=
account_file
)
# Pass any options
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://mp.163.com"
)
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
board
=
page
.
locator
(
"//*[@class='homeV4__board__card__data__value']"
)
# html_content = await board.inner_html()
# print(html_content)
content
=
await
board
.
nth
(
0
)
.
inner_text
()
#总粉丝数
print
(
content
)
content
=
await
board
.
nth
(
1
)
.
inner_text
()
#总阅读数
print
(
content
)
content
=
await
board
.
nth
(
2
)
.
inner_text
()
#总收益
print
(
content
)
await
page
.
get_by_text
(
"粉丝数据"
)
.
click
()
await
page
.
wait_for_timeout
(
5000
)
await
page
.
get_by_text
(
"内容数据"
)
.
click
()
# 自动登陆
await
page
.
wait_for_timeout
(
5000
)
await
page
.
get_by_text
(
"收益数据"
)
.
click
()
frame
=
page
.
frame_locator
(
'//iframe[contains(@id, "x-URS-iframe")]'
)
await
frame
.
locator
(
'[name="email"]'
)
.
fill
(
'liufuhua007@163.com'
)
await
frame
.
locator
(
'[name="password"]'
)
.
fill
(
"Liuyihong1023@"
)
await
frame
.
locator
(
'#dologin'
)
.
click
()
# await page.pause()
await
page
.
wait_for_timeout
(
5000
)
browser
.
close
()
# 点击调试器的继续,保存cookie
await
context
.
storage_state
(
path
=
account_file
)
async
def
get_wyh_cookie
(
account_file
):
print
(
"get_wyh_cookie"
)
async
with
async_playwright
()
as
playwright
:
options
=
{
'args'
:
[
...
...
@@ -67,23 +69,47 @@ async def get_wyh_cookie(account_file):
# Make sure to run headed.
browser
=
await
playwright
.
chromium
.
launch
(
**
options
)
# Setup context however you like.
context
=
await
browser
.
new_context
()
# Pass any options
context
=
await
browser
.
new_context
(
storage_state
=
account_file
)
# 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://mp.163.com"
)
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
await
page
.
pause
()
async
def
open_wyh_main_page
(
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
(
storage_state
=
account_file
)
# 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://mp.163.com"
)
board
=
page
.
locator
(
"//*[@class='homeV4__board__card__data__value']"
)
# html_content = await board.inner_html()
# print(html_content)
content
=
await
board
.
nth
(
0
)
.
inner_text
()
#总粉丝数
print
(
content
)
content
=
await
board
.
nth
(
1
)
.
inner_text
()
#总阅读数
print
(
content
)
content
=
await
board
.
nth
(
2
)
.
inner_text
()
#总收益
print
(
content
)
await
page
.
get_by_text
(
"粉丝数据"
)
.
click
()
await
page
.
wait_for_timeout
(
5000
)
await
page
.
get_by_text
(
"内容数据"
)
.
click
()
await
page
.
wait_for_timeout
(
5000
)
await
page
.
get_by_text
(
"收益数据"
)
.
click
()
await
page
.
wait_for_timeout
(
5000
)
browser
.
close
()
# 自动登陆
await
page
.
wait_for_timeout
(
20000
)
frame
=
page
.
frame_locator
(
'//iframe[contains(@id, "x-URS-iframe")]'
)
await
frame
.
locator
(
'[name="email"]'
)
.
fill
(
'liufuhua007@163.com'
)
await
frame
.
locator
(
'[name="password"]'
)
.
fill
(
"Liuyihong1023@"
)
await
frame
.
locator
(
'#dologin'
)
.
click
()
# await page.pause()
await
page
.
wait_for_timeout
(
15000
)
# 点击调试器的继续,保存cookie
await
context
.
storage_state
(
path
=
account_file
)
...
...
utils/base_social_media.py
View file @
8d267b3
...
...
@@ -22,7 +22,7 @@ def get_supported_social_media() -> List[str]:
def
get_cli_action
()
->
List
[
str
]:
return
[
"upload"
,
"login"
,
"watch"
]
return
[
"upload"
,
"login"
,
"watch"
,
"auto_login"
]
async
def
set_init_script
(
context
):
...
...
Please
register
or
login
to post a comment