Showing
2 changed files
with
32 additions
and
19 deletions
| ... | @@ -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) | ... | ... |
| ... | @@ -85,12 +85,12 @@ class KSVideo(object): | ... | @@ -85,12 +85,12 @@ class KSVideo(object): |
| 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.chromium.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,31 @@ class KSVideo(object): | ... | @@ -104,19 +104,31 @@ 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 | - | 117 | + |
| 118 | - # if not await page.get_by_text("封面编辑").count(): | 118 | + if not await page.get_by_text("封面设置").count(): |
| 119 | - # raise Exception("似乎没有跳转到到编辑页面") | 119 | + raise Exception("似乎没有跳转到到编辑页面") |
| 120 | + | ||
| 121 | + # 等待页面跳转到指定的 URL | ||
| 122 | + # while True: | ||
| 123 | + # # 判断是是否进入视频发布页面,没进入,则自动等待到超时 | ||
| 124 | + # try: | ||
| 125 | + # await page.locator('//html/body/div').wait_for(state="attached") | ||
| 126 | + # break | ||
| 127 | + # except: | ||
| 128 | + # kuaishou_logger.info(f' [-] 正在等待进入视频发布页面...') | ||
| 129 | + # await asyncio.sleep(0.1) | ||
| 130 | + # # if not await page.get_by_text("作品描述").count(): | ||
| 131 | + # # raise Exception("似乎没有跳转到到编辑页面") | ||
| 120 | 132 | ||
| 121 | await asyncio.sleep(1) | 133 | await asyncio.sleep(1) |
| 122 | 134 | ... | ... |
-
Please register or login to post a comment