zoujie
......@@ -12,7 +12,8 @@ from uploader.tk_uploader.main_chrome import tiktok_setup, TiktokVideo
from uploader.wyh_uploader.main import wyh_setup
from uploader.toutiao_uploader.main import toutiao_setup
from utils.base_social_media import get_supported_social_media, get_cli_action, SOCIAL_MEDIA_DOUYIN, \
SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO
SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, \
SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO
from utils.constant import TencentZoneTypes
from utils.files_times import get_title_and_hashtags
......@@ -76,6 +77,8 @@ async def main():
# await xhs_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_TOUTIAO:
await toutiao_setup(str(account_file), handle=True)
elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
await toutiao_setup(str(account_file), handle=True)
elif args.action == 'upload':
title, tags = get_title_and_hashtags(args.video_file)
......
import os
from utils.base_social_media import set_init_script
from utils.files_times import get_absolute_path
from utils.log import kuaishou_logger
from playwright.async_api import Playwright, async_playwright
async def wyh_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_wyh_cookie(account_file)
else:
await open_wyh_main_page(account_file)
return True
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://baijiahao.baidu.com/builder/theme/bjh/login")
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()
async def get_wyh_cookie(account_file):
print("get_wyh_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://baijiahao.baidu.com/builder/theme/bjh/login")
# await page.pause()
# 点击调试器的继续,保存cookie
# await context.storage_state(path=account_file)
# 自动登陆
await page.wait_for_timeout(20000)
await page.get_by_text('注册/登录百家号').click()
await page.pause()
......@@ -11,10 +11,12 @@ SOCIAL_MEDIA_KUAISHOU = "kuaishou"
SOCIAL_MEDIA_WANGYIHAO = 'wangyihao'
SOCIAL_MEDIA_XHS = 'xiaohongshu'
SOCIAL_MEDIA_TOUTIAO = 'toutiao'
SOCIAL_MEDIA_BAIJIAHAO = 'baijiahao'
def get_supported_social_media() -> List[str]:
return [SOCIAL_MEDIA_DOUYIN, SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO]
return [SOCIAL_MEDIA_DOUYIN, SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU,
SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO]
def get_cli_action() -> List[str]:
......