liufuhua007
...@@ -99,10 +99,11 @@ class DouYinVideo(object): ...@@ -99,10 +99,11 @@ class DouYinVideo(object):
99 99
100 async def upload(self, playwright: Playwright) -> None: 100 async def upload(self, playwright: Playwright) -> None:
101 # 使用 Chromium 浏览器启动一个浏览器实例 101 # 使用 Chromium 浏览器启动一个浏览器实例
102 - if self.local_executable_path: 102 + # if self.local_executable_path:
103 - browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path) 103 + # browser = await playwright.chromium.launch(headless=True, executable_path=self.local_executable_path)
104 - else: 104 + # else:
105 - browser = await playwright.chromium.launch(headless=False) 105 + print("test")
106 + browser = await playwright.chromium.launch()
106 # 创建一个浏览器上下文,使用指定的 cookie 文件 107 # 创建一个浏览器上下文,使用指定的 cookie 文件
107 context = await browser.new_context(storage_state=f"{self.account_file}") 108 context = await browser.new_context(storage_state=f"{self.account_file}")
108 context = await set_init_script(context) 109 context = await set_init_script(context)
......
...@@ -83,14 +83,14 @@ class KSVideo(object): ...@@ -83,14 +83,14 @@ class KSVideo(object):
83 async def upload(self, playwright: Playwright) -> None: 83 async def upload(self, playwright: Playwright) -> None:
84 # 使用 Chromium 浏览器启动一个浏览器实例 84 # 使用 Chromium 浏览器启动一个浏览器实例
85 print(self.local_executable_path) 85 print(self.local_executable_path)
86 - if self.local_executable_path: 86 + # if self.local_executable_path:
87 - browser = await playwright.chromium.launch( 87 + # browser = await playwright.chromium.launch(
88 - headless=False, 88 + # headless=True,
89 - executable_path=self.local_executable_path, 89 + # executable_path=self.local_executable_path,
90 - ) 90 + # )
91 - else: 91 + # else:
92 - browser = await playwright.chromium.launch( 92 + browser = await playwright.firefox.launch(
93 - headless=False 93 + headless=True
94 ) # 创建一个浏览器上下文,使用指定的 cookie 文件 94 ) # 创建一个浏览器上下文,使用指定的 cookie 文件
95 context = await browser.new_context(storage_state=f"{self.account_file}") 95 context = await browser.new_context(storage_state=f"{self.account_file}")
96 context = await set_init_script(context) 96 context = await set_init_script(context)
...@@ -104,19 +104,48 @@ class KSVideo(object): ...@@ -104,19 +104,48 @@ class KSVideo(object):
104 # 等待页面跳转到指定的 URL,没进入,则自动等待到超时 104 # 等待页面跳转到指定的 URL,没进入,则自动等待到超时
105 kuaishou_logger.info('正在打开主页...') 105 kuaishou_logger.info('正在打开主页...')
106 await page.wait_for_url("https://cp.kuaishou.com/article/publish/video") 106 await page.wait_for_url("https://cp.kuaishou.com/article/publish/video")
107 - # 点击 "上传视频" 按钮 107 + # # 点击 "上传视频" 按钮
108 - upload_button = page.locator("button[class^='_upload-btn']") 108 + # upload_button = page.locator("button[class^='_upload-btn']")
109 - await upload_button.wait_for(state='visible') # 确保按钮可见 109 + # await upload_button.wait_for(state='visible') # 确保按钮可见
110 - 110 + #
111 - async with page.expect_file_chooser() as fc_info: 111 + # async with page.expect_file_chooser() as fc_info:
112 - await upload_button.click() 112 + # await upload_button.click()
113 - file_chooser = await fc_info.value 113 + # file_chooser = await fc_info.value
114 - await file_chooser.set_files(self.file_path) 114 + # await file_chooser.set_files(self.file_path)
115 - 115 +
116 - await asyncio.sleep(2) 116 + await page.locator("div[class^='_publish-container'] input").set_input_files(self.file_path)
117 + await asyncio.sleep(5)
118 +
119 + # 判断视频是否上传成功,去除引导页
120 + while True:
121 + # 判断视频是否上传成功,去除引导页
122 + try:
123 + skip_button = page.get_by_role('button', name="Skip", exact=True)
124 + if await skip_button.count():
125 + await skip_button.click()
126 + await asyncio.sleep(1)
127 + else:
128 + await asyncio.sleep(1)
129 + break
130 + except:
131 + kuaishou_logger.info(" [-] 视频正在发布中...")
132 + await asyncio.sleep(0.5)
133 + break
117 134
118 - # if not await page.get_by_text("封面编辑").count(): 135 + if not await page.get_by_text("封面设置").count():
119 - # raise Exception("似乎没有跳转到到编辑页面") 136 + raise Exception("似乎没有跳转到到编辑页面")
137 +
138 + # 等待页面跳转到指定的 URL
139 + # while True:
140 + # # 判断是是否进入视频发布页面,没进入,则自动等待到超时
141 + # try:
142 + # await page.locator('//html/body/div').wait_for(state="attached")
143 + # break
144 + # except:
145 + # kuaishou_logger.info(f' [-] 正在等待进入视频发布页面...')
146 + # await asyncio.sleep(0.1)
147 + # # if not await page.get_by_text("作品描述").count():
148 + # # raise Exception("似乎没有跳转到到编辑页面")
120 149
121 await asyncio.sleep(1) 150 await asyncio.sleep(1)
122 151
......
...@@ -64,9 +64,14 @@ async def get_sohu_cookie(account_file): ...@@ -64,9 +64,14 @@ async def get_sohu_cookie(account_file):
64 except: 64 except:
65 pass 65 pass
66 await asyncio.sleep(1) 66 await asyncio.sleep(1)
67 - await page.wait_for_selector("div.user-ico", timeout=50000) 67 + await page.locator("div.hd-login-logo span").nth(1).click()
68 + try:
69 + await page.wait_for_selector("a.hd-fBtn-userlogin img", timeout=100000)
70 + except:
71 + sohu_logger.info("登录超时")
72 + return
68 sohu_logger.info("搜狐视频登录成功") 73 sohu_logger.info("搜狐视频登录成功")
69 - await asyncio.sleep(3) 74 + await asyncio.sleep(1)
70 75
71 # await page.pause() 76 # await page.pause()
72 # 点击调试器的继续,保存cookie 77 # 点击调试器的继续,保存cookie
......
...@@ -137,7 +137,9 @@ class TencentVideo(object): ...@@ -137,7 +137,9 @@ class TencentVideo(object):
137 137
138 async def upload(self, playwright: Playwright) -> None: 138 async def upload(self, playwright: Playwright) -> None:
139 # 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误 139 # 使用 Chromium (这里使用系统内浏览器,用chromium 会造成h264错误
140 - browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path) 140 + # browser = await playwright.chromium.launch(headless=True, executable_path=self.local_executable_path)
141 + browser = await playwright.firefox.launch(headless=True )
142 +
141 # 创建一个浏览器上下文,使用指定的 cookie 文件 143 # 创建一个浏览器上下文,使用指定的 cookie 文件
142 context = await browser.new_context(storage_state=f"{self.account_file}") 144 context = await browser.new_context(storage_state=f"{self.account_file}")
143 context = await set_init_script(context) 145 context = await set_init_script(context)
...@@ -150,8 +152,9 @@ class TencentVideo(object): ...@@ -150,8 +152,9 @@ class TencentVideo(object):
150 # 等待页面跳转到指定的 URL,没进入,则自动等待到超时 152 # 等待页面跳转到指定的 URL,没进入,则自动等待到超时
151 await page.wait_for_url("https://channels.weixin.qq.com/platform/post/create") 153 await page.wait_for_url("https://channels.weixin.qq.com/platform/post/create")
152 # await page.wait_for_selector('input[type="file"]', timeout=10000) 154 # await page.wait_for_selector('input[type="file"]', timeout=10000)
153 - file_input = page.locator('input[type="file"]') 155 + file_input = await page.locator('input[type="file"]').set_input_files(self.file_path)
154 - await file_input.set_input_files(self.file_path) 156 + await page.wait_for_selector(".cover-img-horizontal",state="attached")
157 + # await file_input.set_input_files(self.file_path)
155 # 填充标题和话题 158 # 填充标题和话题
156 await self.add_title_tags(page) 159 await self.add_title_tags(page)
157 # 添加商品 160 # 添加商品
......