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 16:13:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
45365f61dd020fa2a467cf62716975e271af97f9
45365f61
1 parent
4cee7dda
fixbug
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
61 deletions
cli_main.py
uploader/bjh_uploader/main.py
uploader/toutiao_uploader/main.py
uploader/wyh_uploader/main.py
utils/base_social_media.py
cli_main.py
View file @
45365f6
...
...
@@ -72,13 +72,32 @@ 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
)
await
wyh_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
False
)
# 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
)
await
toutiao_setup
(
str
(
account_file
),
handle
=
True
,
auto
=
False
)
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
)
elif
args
.
action
==
'upload'
:
title
,
tags
=
get_title_and_hashtags
(
args
.
video_file
)
...
...
uploader/bjh_uploader/main.py
View file @
45365f6
...
...
@@ -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/toutiao_uploader/main.py
View file @
45365f6
...
...
@@ -6,20 +6,23 @@ 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
get_toutiao_cookie_auto
(
account_file
)
else
:
await
open_
wyh
_main_page
(
account_file
)
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'
:
[
...
...
@@ -39,8 +42,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 +60,44 @@ 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
=
{
'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
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"
)
# 手动授权登录
await
page
.
pause
()
# 点击调试器的继续,保存cookie
await
context
.
storage_state
(
path
=
account_file
)
...
...
uploader/wyh_uploader/main.py
View file @
45365f6
...
...
@@ -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文件'
)
await
get_wyh_cookie
(
account_file
)
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 @
45365f6
...
...
@@ -20,7 +20,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