liufuhua007

add baijiahao

...@@ -12,7 +12,8 @@ from uploader.tk_uploader.main_chrome import tiktok_setup, TiktokVideo ...@@ -12,7 +12,8 @@ from uploader.tk_uploader.main_chrome import tiktok_setup, TiktokVideo
12 from uploader.wyh_uploader.main import wyh_setup 12 from uploader.wyh_uploader.main import wyh_setup
13 from uploader.toutiao_uploader.main import toutiao_setup 13 from uploader.toutiao_uploader.main import toutiao_setup
14 from utils.base_social_media import get_supported_social_media, get_cli_action, SOCIAL_MEDIA_DOUYIN, \ 14 from utils.base_social_media import get_supported_social_media, get_cli_action, SOCIAL_MEDIA_DOUYIN, \
15 - SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO 15 + SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, \
16 + SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO
16 from utils.constant import TencentZoneTypes 17 from utils.constant import TencentZoneTypes
17 from utils.files_times import get_title_and_hashtags 18 from utils.files_times import get_title_and_hashtags
18 19
...@@ -76,6 +77,8 @@ async def main(): ...@@ -76,6 +77,8 @@ async def main():
76 # await xhs_setup(str(account_file), handle=True) 77 # await xhs_setup(str(account_file), handle=True)
77 elif args.platform == SOCIAL_MEDIA_TOUTIAO: 78 elif args.platform == SOCIAL_MEDIA_TOUTIAO:
78 await toutiao_setup(str(account_file), handle=True) 79 await toutiao_setup(str(account_file), handle=True)
80 + elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
81 + await toutiao_setup(str(account_file), handle=True)
79 82
80 elif args.action == 'upload': 83 elif args.action == 'upload':
81 title, tags = get_title_and_hashtags(args.video_file) 84 title, tags = get_title_and_hashtags(args.video_file)
......
1 +import os
2 +
3 +from utils.base_social_media import set_init_script
4 +from utils.files_times import get_absolute_path
5 +from utils.log import kuaishou_logger
6 +from playwright.async_api import Playwright, async_playwright
7 +
8 +
9 +async def wyh_setup(account_file, handle=False):
10 + print(account_file)
11 + account_file = get_absolute_path(account_file, "wyh_uploader")
12 + if not os.path.exists(account_file):
13 + if not handle:
14 + return False
15 + kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
16 + await get_wyh_cookie(account_file)
17 + else:
18 + await open_wyh_main_page(account_file)
19 + return True
20 +
21 +
22 +async def open_wyh_main_page(account_file):
23 + async with async_playwright() as playwright:
24 + options = {
25 + 'args': [
26 + '--lang en-GB'
27 + ],
28 + 'headless': False, # Set headless option here
29 + }
30 + # Make sure to run headed.
31 + browser = await playwright.chromium.launch(**options)
32 + # Setup context however you like.
33 + context = await browser.new_context(storage_state=account_file) # Pass any options
34 + context = await set_init_script(context)
35 + # Pause the page, and start recording manually.
36 + page = await context.new_page()
37 + await page.goto("https://baijiahao.baidu.com/builder/theme/bjh/login")
38 +
39 + board = page.locator("//*[@class='homeV4__board__card__data__value']")
40 + # html_content = await board.inner_html()
41 + # print(html_content)
42 + content = await board.nth(0).inner_text() #总粉丝数
43 + print(content)
44 + content = await board.nth(1).inner_text() #总阅读数
45 + print(content)
46 + content = await board.nth(2).inner_text() #总收益
47 + print(content)
48 +
49 + await page.get_by_text("粉丝数据").click()
50 + await page.wait_for_timeout(5000)
51 + await page.get_by_text("内容数据").click()
52 + await page.wait_for_timeout(5000)
53 + await page.get_by_text("收益数据").click()
54 + await page.wait_for_timeout(5000)
55 + browser.close()
56 +
57 +
58 +async def get_wyh_cookie(account_file):
59 + print("get_wyh_cookie")
60 + async with async_playwright() as playwright:
61 + options = {
62 + 'args': [
63 + '--lang en-GB'
64 + ],
65 + 'headless': False, # Set headless option here
66 + }
67 + # Make sure to run headed.
68 + browser = await playwright.chromium.launch(**options)
69 + # Setup context however you like.
70 + context = await browser.new_context() # Pass any options
71 + context = await set_init_script(context)
72 + # Pause the page, and start recording manually.
73 + page = await context.new_page()
74 + await page.goto("https://baijiahao.baidu.com/builder/theme/bjh/login")
75 + # await page.pause()
76 + # 点击调试器的继续,保存cookie
77 + # await context.storage_state(path=account_file)
78 +
79 + # 自动登陆
80 + await page.wait_for_timeout(20000)
81 + await page.get_by_text('注册/登录百家号').click()
82 + await page.pause()
...@@ -11,10 +11,12 @@ SOCIAL_MEDIA_KUAISHOU = "kuaishou" ...@@ -11,10 +11,12 @@ SOCIAL_MEDIA_KUAISHOU = "kuaishou"
11 SOCIAL_MEDIA_WANGYIHAO = 'wangyihao' 11 SOCIAL_MEDIA_WANGYIHAO = 'wangyihao'
12 SOCIAL_MEDIA_XHS = 'xiaohongshu' 12 SOCIAL_MEDIA_XHS = 'xiaohongshu'
13 SOCIAL_MEDIA_TOUTIAO = 'toutiao' 13 SOCIAL_MEDIA_TOUTIAO = 'toutiao'
14 +SOCIAL_MEDIA_BAIJIAHAO = 'baijiahao'
14 15
15 16
16 def get_supported_social_media() -> List[str]: 17 def get_supported_social_media() -> List[str]:
17 - return [SOCIAL_MEDIA_DOUYIN, SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO] 18 + return [SOCIAL_MEDIA_DOUYIN, SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU,
19 + SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO]
18 20
19 21
20 def get_cli_action() -> List[str]: 22 def get_cli_action() -> List[str]:
......