zoujie

no message

......@@ -99,10 +99,11 @@ class DouYinVideo(object):
async def upload(self, playwright: Playwright) -> None:
# 使用 Chromium 浏览器启动一个浏览器实例
if self.local_executable_path:
browser = await playwright.chromium.launch(headless=False, executable_path=self.local_executable_path)
else:
browser = await playwright.chromium.launch(headless=False)
# if self.local_executable_path:
# browser = await playwright.chromium.launch(headless=True, executable_path=self.local_executable_path)
# else:
print("test")
browser = await playwright.chromium.launch()
# 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(storage_state=f"{self.account_file}")
context = await set_init_script(context)
......
......@@ -85,12 +85,12 @@ class KSVideo(object):
print(self.local_executable_path)
if self.local_executable_path:
browser = await playwright.chromium.launch(
headless=False,
headless=True,
executable_path=self.local_executable_path,
)
else:
browser = await playwright.chromium.launch(
headless=False
headless=True
) # 创建一个浏览器上下文,使用指定的 cookie 文件
context = await browser.new_context(storage_state=f"{self.account_file}")
context = await set_init_script(context)
......@@ -104,19 +104,31 @@ class KSVideo(object):
# 等待页面跳转到指定的 URL,没进入,则自动等待到超时
kuaishou_logger.info('正在打开主页...')
await page.wait_for_url("https://cp.kuaishou.com/article/publish/video")
# 点击 "上传视频" 按钮
upload_button = page.locator("button[class^='_upload-btn']")
await upload_button.wait_for(state='visible') # 确保按钮可见
async with page.expect_file_chooser() as fc_info:
await upload_button.click()
file_chooser = await fc_info.value
await file_chooser.set_files(self.file_path)
await asyncio.sleep(2)
# if not await page.get_by_text("封面编辑").count():
# raise Exception("似乎没有跳转到到编辑页面")
# # 点击 "上传视频" 按钮
# upload_button = page.locator("button[class^='_upload-btn']")
# await upload_button.wait_for(state='visible') # 确保按钮可见
#
# async with page.expect_file_chooser() as fc_info:
# await upload_button.click()
# file_chooser = await fc_info.value
# await file_chooser.set_files(self.file_path)
await page.locator("div[class^='_publish-container'] input").set_input_files(self.file_path)
if not await page.get_by_text("封面设置").count():
raise Exception("似乎没有跳转到到编辑页面")
# 等待页面跳转到指定的 URL
# while True:
# # 判断是是否进入视频发布页面,没进入,则自动等待到超时
# try:
# await page.locator('//html/body/div').wait_for(state="attached")
# break
# except:
# kuaishou_logger.info(f' [-] 正在等待进入视频发布页面...')
# await asyncio.sleep(0.1)
# # if not await page.get_by_text("作品描述").count():
# # raise Exception("似乎没有跳转到到编辑页面")
await asyncio.sleep(1)
......