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
liufuhua007
2024-12-24 17:17:41 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
dfc6117eb0601a4f1a976f526743a0e7b8265dcc
dfc6117e
2 parents
2c9ba9b0
8d267b3e
Merge branch 'master' of
ssh://gitlab.rinal-li.cn:10022/liufuhua/xj-marketing
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
30 deletions
uploader/douyin_uploader/main.py
uploader/ks_uploader/main.py
uploader/sohu_uploader/main.py
uploader/tencent_uploader/main.py
uploader/douyin_uploader/main.py
View file @
dfc6117
...
...
@@ -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 @
dfc6117
...
...
@@ -83,15 +83,15 @@ 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
)
# 创建一个浏览器上下文,使用指定的 cookie 文件
#
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
)
context
.
on
(
"close"
,
lambda
:
context
.
storage_state
(
path
=
self
.
account_file
))
...
...
@@ -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/sohu_uploader/main.py
View file @
dfc6117
...
...
@@ -64,9 +64,14 @@ async def get_sohu_cookie(account_file):
except
:
pass
await
asyncio
.
sleep
(
1
)
await
page
.
wait_for_selector
(
"div.user-ico"
,
timeout
=
50000
)
await
page
.
locator
(
"div.hd-login-logo span"
)
.
nth
(
1
)
.
click
()
try
:
await
page
.
wait_for_selector
(
"a.hd-fBtn-userlogin img"
,
timeout
=
100000
)
except
:
sohu_logger
.
info
(
"登录超时"
)
return
sohu_logger
.
info
(
"搜狐视频登录成功"
)
await
asyncio
.
sleep
(
3
)
await
asyncio
.
sleep
(
1
)
# await page.pause()
# 点击调试器的继续,保存cookie
...
...
uploader/tencent_uploader/main.py
View file @
dfc6117
...
...
@@ -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
)
# 添加商品
...
...
Please
register
or
login
to post a comment