zoujie
...@@ -168,3 +168,6 @@ douyin_uploader/*.json ...@@ -168,3 +168,6 @@ douyin_uploader/*.json
168 bilibili_uploader/*.json 168 bilibili_uploader/*.json
169 tk_uploader/*.json 169 tk_uploader/*.json
170 cookies 170 cookies
171 +bin
172 +get-pip.py
173 +pyvenv.cfg
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -11,10 +11,11 @@ from uploader.tencent_uploader.main import weixin_setup, TencentVideo ...@@ -11,10 +11,11 @@ from uploader.tencent_uploader.main import weixin_setup, TencentVideo
11 from uploader.tk_uploader.main_chrome import tiktok_setup, TiktokVideo 11 from uploader.tk_uploader.main_chrome import tiktok_setup, TiktokVideo
12 from uploader.xhs_uploader.main import xhs_setup, XHSVideo 12 from uploader.xhs_uploader.main import xhs_setup, XHSVideo
13 from uploader.wyh_uploader.main import wyh_setup 13 from uploader.wyh_uploader.main import wyh_setup
14 +from uploader.sohu_uploader.main import sohu_setup, SOHUVideo
14 from uploader.toutiao_uploader.main import toutiao_setup 15 from uploader.toutiao_uploader.main import toutiao_setup
15 from utils.base_social_media import get_supported_social_media, get_cli_action, SOCIAL_MEDIA_DOUYIN, \ 16 from utils.base_social_media import get_supported_social_media, get_cli_action, SOCIAL_MEDIA_DOUYIN, \
16 SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, \ 17 SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, SOCIAL_MEDIA_WANGYIHAO, \
17 - SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO 18 + SOCIAL_MEDIA_XHS, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO, SOCIAL_MEDIA_SOHU
18 from utils.constant import TencentZoneTypes 19 from utils.constant import TencentZoneTypes
19 from utils.files_times import get_title_and_hashtags 20 from utils.files_times import get_title_and_hashtags
20 21
...@@ -73,13 +74,40 @@ async def main(): ...@@ -73,13 +74,40 @@ async def main():
73 elif args.platform == SOCIAL_MEDIA_KUAISHOU: 74 elif args.platform == SOCIAL_MEDIA_KUAISHOU:
74 await ks_setup(str(account_file), handle=True) 75 await ks_setup(str(account_file), handle=True)
75 elif args.platform == SOCIAL_MEDIA_WANGYIHAO: 76 elif args.platform == SOCIAL_MEDIA_WANGYIHAO:
77 + await wyh_setup(str(account_file), handle=True, auto=False)
78 + # elif args.platform == SOCIAL_MEDIA_XHS:
79 + # await xhs_setup(str(account_file), handle=True)
76 await wyh_setup(str(account_file), handle=True) 80 await wyh_setup(str(account_file), handle=True)
77 elif args.platform == SOCIAL_MEDIA_XHS: 81 elif args.platform == SOCIAL_MEDIA_XHS:
78 await xhs_setup(str(account_file), handle=True) 82 await xhs_setup(str(account_file), handle=True)
79 elif args.platform == SOCIAL_MEDIA_TOUTIAO: 83 elif args.platform == SOCIAL_MEDIA_TOUTIAO:
80 - await toutiao_setup(str(account_file), handle=True) 84 + await toutiao_setup(str(account_file), handle=True, auto=False)
85 + elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
86 + await toutiao_setup(str(account_file), handle=True, auto=False)
87 + elif args.platform == SOCIAL_MEDIA_SOHU:
88 + await sohu_setup(str(account_file), handle=True)
89 +
90 + elif args.action == 'auto_login':
91 + print(f"auto Logging in with account {args.account_name} on platform {args.platform}")
92 + if args.platform == SOCIAL_MEDIA_DOUYIN:
93 + await douyin_setup(str(account_file), handle=True)
94 + elif args.platform == SOCIAL_MEDIA_TIKTOK:
95 + await tiktok_setup(str(account_file), handle=True)
96 + elif args.platform == SOCIAL_MEDIA_TENCENT:
97 + await weixin_setup(str(account_file), handle=True)
98 + elif args.platform == SOCIAL_MEDIA_KUAISHOU:
99 + await ks_setup(str(account_file), handle=True)
100 + elif args.platform == SOCIAL_MEDIA_WANGYIHAO:
101 + await wyh_setup(str(account_file), handle=True, auto=True)
102 + # elif args.platform == SOCIAL_MEDIA_XHS:
103 + # await xhs_setup(str(account_file), handle=True)
104 + elif args.platform == SOCIAL_MEDIA_TOUTIAO:
105 + await toutiao_setup(str(account_file), handle=True, auto=True)
81 elif args.platform == SOCIAL_MEDIA_BAIJIAHAO: 106 elif args.platform == SOCIAL_MEDIA_BAIJIAHAO:
107 + await toutiao_setup(str(account_file), handle=True, auto=True)
82 await toutiao_setup(str(account_file), handle=True) 108 await toutiao_setup(str(account_file), handle=True)
109 + elif args.platform == SOCIAL_MEDIA_SOHU:
110 + await sohu_setup(str(account_file), handle=True)
83 111
84 elif args.action == 'upload': 112 elif args.action == 'upload':
85 title, tags = get_title_and_hashtags(args.video_file) 113 title, tags = get_title_and_hashtags(args.video_file)
...@@ -108,6 +136,9 @@ async def main(): ...@@ -108,6 +136,9 @@ async def main():
108 elif args.platform == SOCIAL_MEDIA_XHS: 136 elif args.platform == SOCIAL_MEDIA_XHS:
109 await xhs_setup(account_file, handle=True) 137 await xhs_setup(account_file, handle=True)
110 app = XHSVideo(title, video_file, tags, publish_date, account_file) 138 app = XHSVideo(title, video_file, tags, publish_date, account_file)
139 + elif args.platform == SOCIAL_MEDIA_SOHU:
140 + await sohu_setup(account_file, handle=True)
141 + app = SOHUVideo(title, video_file, tags, None, account_file)
111 else: 142 else:
112 print("Wrong platform, please check your input") 143 print("Wrong platform, please check your input")
113 exit() 144 exit()
......
...@@ -6,20 +6,20 @@ from utils.log import kuaishou_logger ...@@ -6,20 +6,20 @@ from utils.log import kuaishou_logger
6 from playwright.async_api import Playwright, async_playwright 6 from playwright.async_api import Playwright, async_playwright
7 7
8 8
9 -async def wyh_setup(account_file, handle=False): 9 +async def bjh_setup(account_file, handle=False):
10 print(account_file) 10 print(account_file)
11 account_file = get_absolute_path(account_file, "wyh_uploader") 11 account_file = get_absolute_path(account_file, "wyh_uploader")
12 if not os.path.exists(account_file): 12 if not os.path.exists(account_file):
13 if not handle: 13 if not handle:
14 return False 14 return False
15 kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') 15 kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
16 - await get_wyh_cookie(account_file) 16 + await get_bjh_cookie(account_file)
17 else: 17 else:
18 - await open_wyh_main_page(account_file) 18 + await open_bjh_main_page(account_file)
19 return True 19 return True
20 20
21 21
22 -async def open_wyh_main_page(account_file): 22 +async def open_bjh_main_page(account_file):
23 async with async_playwright() as playwright: 23 async with async_playwright() as playwright:
24 options = { 24 options = {
25 'args': [ 25 'args': [
...@@ -55,7 +55,7 @@ async def open_wyh_main_page(account_file): ...@@ -55,7 +55,7 @@ async def open_wyh_main_page(account_file):
55 browser.close() 55 browser.close()
56 56
57 57
58 -async def get_wyh_cookie(account_file): 58 +async def get_bjh_cookie(account_file):
59 print("get_wyh_cookie") 59 print("get_wyh_cookie")
60 async with async_playwright() as playwright: 60 async with async_playwright() as playwright:
61 options = { 61 options = {
...@@ -77,6 +77,12 @@ async def get_wyh_cookie(account_file): ...@@ -77,6 +77,12 @@ async def get_wyh_cookie(account_file):
77 # await context.storage_state(path=account_file) 77 # await context.storage_state(path=account_file)
78 78
79 # 自动登陆 79 # 自动登陆
80 - await page.wait_for_timeout(20000) 80 + await page.wait_for_timeout(2000)
81 await page.get_by_text('注册/登录百家号').click() 81 await page.get_by_text('注册/登录百家号').click()
82 - await page.pause() 82 + await page.wait_for_timeout(2000)
83 + await page.locator("//*[@class='pass-text-input pass-text-input-userName']").fill("idiotbc")
84 + await page.wait_for_timeout(2000)
85 + await page.locator("//*[@class='pass-text-input pass-text-input-password']").fill("Liuyihong1023@")
86 + await page.wait_for_timeout(2000)
87 + await page.locator("//*[@class='pass-checkbox-input pass-checkbox-isAgree']").click()
88 + await page.wait_for_timeout(2000)
......
1 +# -*- coding: utf-8 -*-
2 +from datetime import datetime
3 +
4 +from playwright.async_api import Playwright, async_playwright
5 +import os
6 +import asyncio
7 +import json
8 +from conf import LOCAL_CHROME_PATH
9 +from utils.base_social_media import set_init_script
10 +from utils.files_times import get_absolute_path
11 +from utils.log import sohu_logger
12 +
13 +
14 +async def cookie_auth(account_file):
15 + async with async_playwright() as playwright:
16 + browser = await playwright.chromium.launch(headless=True)
17 + context = await browser.new_context(storage_state=account_file)
18 + await set_init_script(context)
19 + # context = await browser.new_context()
20 + page = await context.new_page()
21 + # saved_cookies = await read_cookies_from_file(account_file)
22 + # await context.add_cookies(saved_cookies)
23 + try:
24 + await page.goto("https://tv.sohu.com/", timeout=5000)
25 + except:
26 + pass
27 + try:
28 + await page.wait_for_selector("div.user-ico", timeout=5000) # 等待5秒
29 + sohu_logger.success("[+] cookie 有效")
30 + return True
31 + except:
32 + sohu_logger.info("[+] 等待5秒 cookie 失效")
33 + return False
34 +
35 +
36 +async def sohu_setup(account_file, handle=False):
37 + account_file = get_absolute_path(account_file, "sohu_uploader")
38 + if not os.path.exists(account_file) or not await cookie_auth(account_file):
39 + if not handle:
40 + return False
41 + sohu_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
42 + await get_sohu_cookie(account_file)
43 + return True
44 +
45 +
46 +async def get_sohu_cookie(account_file):
47 + async with async_playwright() as playwright:
48 + options = {
49 + 'args': [
50 + '--lang en-GB'
51 + ],
52 + 'headless': True, # Set headless option here
53 + }
54 + # Make sure to run headed.
55 + browser = await playwright.chromium.launch(**options)
56 + # Setup context however you like.
57 + context = await browser.new_context() # Pass any options
58 + context = await set_init_script(context)
59 + # Pause the page, and start recording manually.
60 + page = await context.new_page()
61 + try:
62 + await page.goto("https://tv.sohu.com/", timeout=5000)
63 + except:
64 + pass
65 + await asyncio.sleep(1)
66 + await page.wait_for_selector("div.user-ico", timeout=50000)
67 + sohu_logger.info("搜狐视频登录成功")
68 + await asyncio.sleep(3)
69 +
70 + # await page.pause()
71 + # 点击调试器的继续,保存cookie
72 + # cookies = await context.cookies()
73 + # await write_cookies_to_file(cookies, account_file)
74 + await context.storage_state(path=account_file)
75 +
76 +
77 +class SOHUVideo(object):
78 + def __init__(self, title, file_path, tags, publish_date: datetime, account_file):
79 + self.title = title # 视频标题
80 + self.file_path = file_path
81 + self.tags = tags
82 + self.publish_date = publish_date
83 + self.account_file = account_file
84 + self.date_format = '%Y-%m-%d %H:%M'
85 + self.local_executable_path = LOCAL_CHROME_PATH
86 +
87 + async def handle_upload_error(self, page):
88 + pass
89 + # sohu_logger.error("视频出错了,重新上传中")
90 + # await page.locator('div.progress-div [class^="upload-btn-input"]').set_input_files(self.file_path)
91 +
92 + async def upload(self, playwright: Playwright) -> None:
93 + # 使用 Chromium 浏览器启动一个浏览器实例
94 + if self.local_executable_path:
95 + browser = await playwright.chromium.launch(
96 + headless=False,
97 + executable_path=self.local_executable_path,
98 + )
99 + else:
100 + browser = await playwright.chromium.launch(
101 + headless=True
102 + ) # 创建一个浏览器上下文,使用指定的 cookie 文件
103 + context = await browser.new_context(storage_state=self.account_file)
104 + page = await context.new_page()
105 + # saved_cookies = await read_cookies_from_file(self.account_file)
106 + # await context.add_cookies(saved_cookies)
107 + # context = await set_init_script(context)
108 + # context.on("close", lambda: )
109 +
110 + # 创建一个新的页面
111 + # 访问指定的 URL
112 + try:
113 + await page.goto("https://tv.sohu.com/s/center/index.html#/", timeout=5000)
114 + except:
115 + pass
116 + sohu_logger.info('正在上传-------{}.mp4'.format(self.title))
117 + # 等待页面跳转到指定的 URL,没进入,则自动等待到超时
118 + # 点击 "上传视频" 按钮
119 +
120 + # await page.locator("dev.release-top").set_input_files(
121 + # self.file_path)
122 + await page.locator("input[type='file']").set_input_files(
123 + self.file_path)
124 +
125 + upload_button = page.locator('div.form-button span:has-text("发布")')
126 + await upload_button.wait_for(state='visible') # 确保按钮可见
127 + await asyncio.sleep(1)
128 +
129 + sohu_logger.info("正在填充标题...")
130 + await page.locator("input.input-topic").nth(0).fill(self.title[:99]) # 搜狐最多100
131 + await asyncio.sleep(1)
132 + sohu_logger.info("正在填充话题...")
133 + inputTag = page.locator("input.input-topic").nth(1)
134 + await inputTag.click()
135 + for index, tag in enumerate(self.tags[:2], start=1):
136 + await page.keyboard.type(f"#{tag}")
137 + await page.keyboard.press("Enter")
138 +
139 +
140 + sohu_logger.info("已写完tag")
141 + await asyncio.sleep(1)
142 +
143 + sohu_logger.info(self.publish_date)
144 + # 定时任务 搜狐没有定时发布
145 + # if self.publish_date != 0:
146 + # await self.set_schedule_time(page, self.publish_date)
147 + # upload_button = page.locator('button div span:has-text("定时发布")')
148 + sohu_logger.info("提交")
149 + await upload_button.click()
150 + await page.wait_for_selector('h3:has-text("视频管理")')
151 + await context.storage_state(path=self.account_file)
152 + sohu_logger.info('cookie更新完毕!')
153 + await asyncio.sleep(4) # 这里延迟是为了方便眼睛直观的观看
154 + # 关闭浏览器上下文和浏览器实例
155 + await context.close()
156 + await browser.close()
157 +
158 + async def main(self):
159 + async with async_playwright() as playwright:
160 + await self.upload(playwright)
161 +
162 +
...@@ -6,25 +6,25 @@ from utils.log import kuaishou_logger ...@@ -6,25 +6,25 @@ from utils.log import kuaishou_logger
6 from playwright.async_api import Playwright, async_playwright 6 from playwright.async_api import Playwright, async_playwright
7 7
8 8
9 -async def toutiao_setup(account_file, handle=False): 9 +async def toutiao_setup(account_file, handle=False, auto=False):
10 print(account_file) 10 print(account_file)
11 account_file = get_absolute_path(account_file, "wyh_uploader") 11 account_file = get_absolute_path(account_file, "wyh_uploader")
12 if not os.path.exists(account_file): 12 if not os.path.exists(account_file):
13 if not handle: 13 if not handle:
14 return False 14 return False
15 kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') 15 kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
16 - await get_wyh_cookie(account_file) 16 + if not auto:
17 + await get_toutiao_cookie(account_file)
17 else: 18 else:
18 - await open_wyh_main_page(account_file) 19 + await get_toutiao_cookie_auto(account_file)
20 + else:
21 + await open_toutiao_main_page(account_file)
19 return True 22 return True
20 23
21 24
22 -async def open_wyh_main_page(account_file): 25 +async def open_toutiao_main_page(account_file):
23 async with async_playwright() as playwright: 26 async with async_playwright() as playwright:
24 options = { 27 options = {
25 - 'args': [
26 - '--lang en-GB'
27 - ],
28 'headless': False, # Set headless option here 28 'headless': False, # Set headless option here
29 } 29 }
30 # Make sure to run headed. 30 # Make sure to run headed.
...@@ -39,8 +39,8 @@ async def open_wyh_main_page(account_file): ...@@ -39,8 +39,8 @@ async def open_wyh_main_page(account_file):
39 browser.close() 39 browser.close()
40 40
41 41
42 -async def get_wyh_cookie(account_file): 42 +async def get_toutiao_cookie_auto(account_file):
43 - print("get_wyh_cookie") 43 + print("get_toutiao_cookie")
44 async with async_playwright() as playwright: 44 async with async_playwright() as playwright:
45 options = { 45 options = {
46 'args': [ 46 'args': [
...@@ -57,24 +57,41 @@ async def get_wyh_cookie(account_file): ...@@ -57,24 +57,41 @@ async def get_wyh_cookie(account_file):
57 page = await context.new_page() 57 page = await context.new_page()
58 await page.goto("https://mp.toutiao.com") 58 await page.goto("https://mp.toutiao.com")
59 59
60 - # 手动授权登录
61 - # await page.pause()
62 - # 点击调试器的继续,保存cookie
63 - # await context.storage_state(path=account_file)
64 -
65 # 自动登陆 60 # 自动登陆
66 - await page.wait_for_timeout(5000) 61 + await page.wait_for_timeout(2000)
67 await page.get_by_text('密码登录').click() 62 await page.get_by_text('密码登录').click()
68 - await page.wait_for_timeout(5000) 63 + await page.wait_for_timeout(2000)
69 64
70 await page.get_by_placeholder("手机号/邮箱").fill('18610534668') 65 await page.get_by_placeholder("手机号/邮箱").fill('18610534668')
71 print("输入账号成功") 66 print("输入账号成功")
72 await page.wait_for_timeout(1000) 67 await page.wait_for_timeout(1000)
73 await page.get_by_placeholder('密码').fill("Liuyihong1023@") 68 await page.get_by_placeholder('密码').fill("Liuyihong1023@")
74 - await page.wait_for_timeout(1000) 69 + await page.wait_for_timeout(2000)
75 await page.locator("//*[@class='web-login-confirm-info__checkbox']").click() 70 await page.locator("//*[@class='web-login-confirm-info__checkbox']").click()
76 - await page.wait_for_timeout(1000) 71 + await page.wait_for_timeout(2000)
77 await page.locator("//*[@class='web-login-button']").click() 72 await page.locator("//*[@class='web-login-button']").click()
78 - await page.wait_for_timeout(10000) 73 + await page.wait_for_timeout(2000)
74 + # 点击调试器的继续,保存cookie
75 + await context.storage_state(path=account_file)
76 +
77 +
78 +async def get_toutiao_cookie(account_file):
79 + print("get_toutiao_cookie")
80 + async with async_playwright() as playwright:
81 + options = {
82 + 'headless': False, # Set headless option here
83 + }
84 + # Make sure to run headed.
85 + browser = await playwright.chromium.launch(**options)
86 + # Setup context however you like.
87 + context = await browser.new_context() # Pass any options
88 + context = await set_init_script(context)
89 + # Pause the page, and start recording manually.
90 + page = await context.new_page()
91 + await page.goto("https://mp.toutiao.com", {waitUntil: "commit"})
92 +
93 + # 手动授权登录
94 + await page.pause()
79 # 点击调试器的继续,保存cookie 95 # 点击调试器的继续,保存cookie
80 await context.storage_state(path=account_file) 96 await context.storage_state(path=account_file)
97 +
......
...@@ -6,20 +6,26 @@ from utils.log import kuaishou_logger ...@@ -6,20 +6,26 @@ from utils.log import kuaishou_logger
6 from playwright.async_api import Playwright, async_playwright 6 from playwright.async_api import Playwright, async_playwright
7 7
8 8
9 -async def wyh_setup(account_file, handle=False): 9 +async def wyh_setup(account_file, handle=False, auto=False):
10 print(account_file) 10 print(account_file)
11 account_file = get_absolute_path(account_file, "wyh_uploader") 11 account_file = get_absolute_path(account_file, "wyh_uploader")
12 if not os.path.exists(account_file): 12 if not os.path.exists(account_file):
13 if not handle: 13 if not handle:
14 return False 14 return False
15 kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件') 15 kuaishou_logger.info('[+] cookie文件不存在或已失效,即将自动打开浏览器,请扫码登录,登陆后会自动生成cookie文件')
16 + if not auto:
16 await get_wyh_cookie(account_file) 17 await get_wyh_cookie(account_file)
17 else: 18 else:
19 + await get_wyh_cookie_auto(account_file)
20 + else:
18 await open_wyh_main_page(account_file) 21 await open_wyh_main_page(account_file)
19 return True 22 return True
20 23
21 24
22 -async def open_wyh_main_page(account_file): 25 +'''
26 +'''
27 +async def get_wyh_cookie_auto(account_file):
28 + print("get_wyh_cookie")
23 async with async_playwright() as playwright: 29 async with async_playwright() as playwright:
24 options = { 30 options = {
25 'args': [ 31 'args': [
...@@ -30,33 +36,29 @@ async def open_wyh_main_page(account_file): ...@@ -30,33 +36,29 @@ async def open_wyh_main_page(account_file):
30 # Make sure to run headed. 36 # Make sure to run headed.
31 browser = await playwright.chromium.launch(**options) 37 browser = await playwright.chromium.launch(**options)
32 # Setup context however you like. 38 # Setup context however you like.
33 - context = await browser.new_context(storage_state=account_file) # Pass any options 39 + context = await browser.new_context() # Pass any options
34 context = await set_init_script(context) 40 context = await set_init_script(context)
35 # Pause the page, and start recording manually. 41 # Pause the page, and start recording manually.
36 page = await context.new_page() 42 page = await context.new_page()
37 await page.goto("https://mp.163.com") 43 await page.goto("https://mp.163.com")
44 + # await page.pause()
45 + # 点击调试器的继续,保存cookie
46 + # await context.storage_state(path=account_file)
38 47
39 - board = page.locator("//*[@class='homeV4__board__card__data__value']") 48 + # 自动登陆
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) 49 await page.wait_for_timeout(5000)
53 - await page.get_by_text("收益数据").click() 50 + frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]')
51 + await frame.locator('[name="email"]').fill('liufuhua007@163.com')
52 + await frame.locator('[name="password"]').fill("Liuyihong1023@")
53 + await frame.locator('#dologin').click()
54 +
55 + # await page.pause()
54 await page.wait_for_timeout(5000) 56 await page.wait_for_timeout(5000)
55 - browser.close() 57 + # 点击调试器的继续,保存cookie
58 + await context.storage_state(path=account_file)
56 59
57 60
58 async def get_wyh_cookie(account_file): 61 async def get_wyh_cookie(account_file):
59 - print("get_wyh_cookie")
60 async with async_playwright() as playwright: 62 async with async_playwright() as playwright:
61 options = { 63 options = {
62 'args': [ 64 'args': [
...@@ -67,23 +69,47 @@ async def get_wyh_cookie(account_file): ...@@ -67,23 +69,47 @@ async def get_wyh_cookie(account_file):
67 # Make sure to run headed. 69 # Make sure to run headed.
68 browser = await playwright.chromium.launch(**options) 70 browser = await playwright.chromium.launch(**options)
69 # Setup context however you like. 71 # Setup context however you like.
70 - context = await browser.new_context() # Pass any options 72 + context = await browser.new_context(storage_state=account_file) # Pass any options
71 context = await set_init_script(context) 73 context = await set_init_script(context)
72 # Pause the page, and start recording manually. 74 # Pause the page, and start recording manually.
73 page = await context.new_page() 75 page = await context.new_page()
74 await page.goto("https://mp.163.com") 76 await page.goto("https://mp.163.com")
75 - # await page.pause() 77 + await page.pause()
76 - # 点击调试器的继续,保存cookie 78 +
77 - # await context.storage_state(path=account_file) 79 +
80 +async def open_wyh_main_page(account_file):
81 + async with async_playwright() as playwright:
82 + options = {
83 + 'args': [
84 + '--lang en-GB'
85 + ],
86 + 'headless': False, # Set headless option here
87 + }
88 + # Make sure to run headed.
89 + browser = await playwright.chromium.launch(**options)
90 + # Setup context however you like.
91 + context = await browser.new_context(storage_state=account_file) # Pass any options
92 + context = await set_init_script(context)
93 + # Pause the page, and start recording manually.
94 + page = await context.new_page()
95 + await page.goto("https://mp.163.com")
96 +
97 + board = page.locator("//*[@class='homeV4__board__card__data__value']")
98 + # html_content = await board.inner_html()
99 + # print(html_content)
100 + content = await board.nth(0).inner_text() #总粉丝数
101 + print(content)
102 + content = await board.nth(1).inner_text() #总阅读数
103 + print(content)
104 + content = await board.nth(2).inner_text() #总收益
105 + print(content)
106 +
107 + await page.get_by_text("粉丝数据").click()
108 + await page.wait_for_timeout(5000)
109 + await page.get_by_text("内容数据").click()
110 + await page.wait_for_timeout(5000)
111 + await page.get_by_text("收益数据").click()
112 + await page.wait_for_timeout(5000)
113 + browser.close()
78 114
79 - # 自动登陆
80 - await page.wait_for_timeout(20000)
81 - frame = page.frame_locator('//iframe[contains(@id, "x-URS-iframe")]')
82 - await frame.locator('[name="email"]').fill('liufuhua007@163.com')
83 - await frame.locator('[name="password"]').fill("Liuyihong1023@")
84 - await frame.locator('#dologin').click()
85 115
86 - # await page.pause()
87 - await page.wait_for_timeout(15000)
88 - # 点击调试器的继续,保存cookie
89 - await context.storage_state(path=account_file)
......
...@@ -25,7 +25,6 @@ async def read_cookies_from_file(file_path): ...@@ -25,7 +25,6 @@ async def read_cookies_from_file(file_path):
25 return [] 25 return []
26 26
27 async def cookie_auth(account_file): 27 async def cookie_auth(account_file):
28 - print(account_file)
29 async with async_playwright() as playwright: 28 async with async_playwright() as playwright:
30 browser = await playwright.chromium.launch(headless=True) 29 browser = await playwright.chromium.launch(headless=True)
31 # context = await browser.new_context(storage_state=account_file) 30 # context = await browser.new_context(storage_state=account_file)
...@@ -35,7 +34,6 @@ async def cookie_auth(account_file): ...@@ -35,7 +34,6 @@ async def cookie_auth(account_file):
35 await context.add_cookies(saved_cookies) 34 await context.add_cookies(saved_cookies)
36 await page.goto("https://www.xiaohongshu.com") 35 await page.goto("https://www.xiaohongshu.com")
37 try: 36 try:
38 - print(await page.title())
39 await page.wait_for_selector("div.link-wrapper a.link-wrapper span.channel", timeout=5000) # 等待5秒 37 await page.wait_for_selector("div.link-wrapper a.link-wrapper span.channel", timeout=5000) # 等待5秒
40 xhs_logger.success("[+] cookie 有效") 38 xhs_logger.success("[+] cookie 有效")
41 return True 39 return True
...@@ -72,12 +70,11 @@ async def get_xhs_cookie(account_file): ...@@ -72,12 +70,11 @@ async def get_xhs_cookie(account_file):
72 await page.goto("https://www.xiaohongshu.com") 70 await page.goto("https://www.xiaohongshu.com")
73 await asyncio.sleep(1) 71 await asyncio.sleep(1)
74 await page.wait_for_selector("div.link-wrapper a.link-wrapper span.channel", timeout=50000) 72 await page.wait_for_selector("div.link-wrapper a.link-wrapper span.channel", timeout=50000)
75 - print("小红书登录成功") 73 + xhs_logger.info("小红书登录成功")
76 await asyncio.sleep(3) 74 await asyncio.sleep(3)
77 75
78 # await page.pause() 76 # await page.pause()
79 # 点击调试器的继续,保存cookie 77 # 点击调试器的继续,保存cookie
80 - await asyncio.sleep(3)
81 cookies = await context.cookies() 78 cookies = await context.cookies()
82 await write_cookies_to_file(cookies, account_file) 79 await write_cookies_to_file(cookies, account_file)
83 80
...@@ -93,8 +90,7 @@ class XHSVideo(object): ...@@ -93,8 +90,7 @@ class XHSVideo(object):
93 self.local_executable_path = LOCAL_CHROME_PATH 90 self.local_executable_path = LOCAL_CHROME_PATH
94 91
95 async def handle_upload_error(self, page): 92 async def handle_upload_error(self, page):
96 - xhs_logger.error("视频出错了,重新上传中") 93 + pass
97 - await page.locator('div.progress-div [class^="upload-btn-input"]').set_input_files(self.file_path)
98 94
99 async def upload(self, playwright: Playwright) -> None: 95 async def upload(self, playwright: Playwright) -> None:
100 # 使用 Chromium 浏览器启动一个浏览器实例 96 # 使用 Chromium 浏览器启动一个浏览器实例
...@@ -129,22 +125,25 @@ class XHSVideo(object): ...@@ -129,22 +125,25 @@ class XHSVideo(object):
129 125
130 126
131 xhs_logger.info("正在填充标题和话题...") 127 xhs_logger.info("正在填充标题和话题...")
132 - await page.locator("div.titleInput div div input").fill("花花") 128 + await page.locator("div.titleInput div div input").fill(self.title[:19]) # 小红书最长20
133 129
134 inputTag = page.locator('id=quillEditor').locator('div p') 130 inputTag = page.locator('id=quillEditor').locator('div p')
135 await inputTag.click() 131 await inputTag.click()
136 for index, tag in enumerate(self.tags, start=1): 132 for index, tag in enumerate(self.tags, start=1):
137 - await page.keyboard.type(f"#{tag} ") 133 + await page.keyboard.type(f"#{tag}")
138 - await asyncio.sleep(2) 134 + await page.wait_for_selector("ul.ql-mention-list")
135 + await page.keyboard.press("Enter")
136 +
139 137
140 xhs_logger.info("已写完tag") 138 xhs_logger.info("已写完tag")
141 await asyncio.sleep(1) 139 await asyncio.sleep(1)
142 140
141 + xhs_logger.info(self.publish_date)
143 # 定时任务 142 # 定时任务
144 if self.publish_date != 0: 143 if self.publish_date != 0:
145 await self.set_schedule_time(page, self.publish_date) 144 await self.set_schedule_time(page, self.publish_date)
146 upload_button = page.locator('button div span:has-text("定时发布")') 145 upload_button = page.locator('button div span:has-text("定时发布")')
147 - 146 + xhs_logger.info("提交")
148 await upload_button.click() 147 await upload_button.click()
149 await page.wait_for_selector('p:has-text("发布成功")') 148 await page.wait_for_selector('p:has-text("发布成功")')
150 await write_cookies_to_file(await context.cookies(), self.account_file) 149 await write_cookies_to_file(await context.cookies(), self.account_file)
......
...@@ -9,18 +9,20 @@ SOCIAL_MEDIA_TIKTOK = "tiktok" ...@@ -9,18 +9,20 @@ SOCIAL_MEDIA_TIKTOK = "tiktok"
9 SOCIAL_MEDIA_BILIBILI = "bilibili" 9 SOCIAL_MEDIA_BILIBILI = "bilibili"
10 SOCIAL_MEDIA_KUAISHOU = "kuaishou" 10 SOCIAL_MEDIA_KUAISHOU = "kuaishou"
11 SOCIAL_MEDIA_WANGYIHAO = 'wangyihao' 11 SOCIAL_MEDIA_WANGYIHAO = 'wangyihao'
12 -SOCIAL_MEDIA_XHS = 'xiaohongshu' 12 +SOCIAL_MEDIA_XHS = 'xiaohongshu' # 小红书最长标题是20
13 SOCIAL_MEDIA_TOUTIAO = 'toutiao' 13 SOCIAL_MEDIA_TOUTIAO = 'toutiao'
14 SOCIAL_MEDIA_BAIJIAHAO = 'baijiahao' 14 SOCIAL_MEDIA_BAIJIAHAO = 'baijiahao'
15 +SOCIAL_MEDIA_SOHU = 'sohu' # 搜狐视频话题最多2个 标题最多100 标题不支持‍🩹
15 16
16 17
17 def get_supported_social_media() -> List[str]: 18 def get_supported_social_media() -> List[str]:
18 return [SOCIAL_MEDIA_DOUYIN, SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU, 19 return [SOCIAL_MEDIA_DOUYIN, SOCIAL_MEDIA_TENCENT, SOCIAL_MEDIA_TIKTOK, SOCIAL_MEDIA_KUAISHOU,
19 - SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO, SOCIAL_MEDIA_XHS] 20 + SOCIAL_MEDIA_WANGYIHAO, SOCIAL_MEDIA_TOUTIAO, SOCIAL_MEDIA_BAIJIAHAO, SOCIAL_MEDIA_XHS,
21 + SOCIAL_MEDIA_SOHU]
20 22
21 23
22 def get_cli_action() -> List[str]: 24 def get_cli_action() -> List[str]:
23 - return ["upload", "login", "watch"] 25 + return ["upload", "login", "watch", "auto_login"]
24 26
25 27
26 async def set_init_script(context): 28 async def set_init_script(context):
......
...@@ -46,6 +46,7 @@ logger.add(stdout, colorize=True, format=log_formatter) ...@@ -46,6 +46,7 @@ logger.add(stdout, colorize=True, format=log_formatter)
46 douyin_logger = create_logger('douyin', 'logs/douyin.log') 46 douyin_logger = create_logger('douyin', 'logs/douyin.log')
47 tencent_logger = create_logger('tencent', 'logs/tencent.log') 47 tencent_logger = create_logger('tencent', 'logs/tencent.log')
48 xhs_logger = create_logger('xhs', 'logs/xhs.log') 48 xhs_logger = create_logger('xhs', 'logs/xhs.log')
49 +sohu_logger = create_logger('sohu', 'logs/sohu.log')
49 tiktok_logger = create_logger('tiktok', 'logs/tiktok.log') 50 tiktok_logger = create_logger('tiktok', 'logs/tiktok.log')
50 bilibili_logger = create_logger('bilibili', 'logs/bilibili.log') 51 bilibili_logger = create_logger('bilibili', 'logs/bilibili.log')
51 kuaishou_logger = create_logger('kuaishou', 'logs/kuaishou.log') 52 kuaishou_logger = create_logger('kuaishou', 'logs/kuaishou.log')
......