wangzhibo
2025-08-04 f5106b912f1261fe633aa6bcdf10a4b7e74345aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from playwright.async_api import async_playwright
from auto_media_publisher.uploaders.login_chrome import LoginChrome
 
class LoginChromeCDP(LoginChrome):
    def __init__(self, user,platform,proxy=None):
        if proxy is None:
            proxy = "http://127.0.0.1:7890"
        super().__init__(user,platform,proxy)
      
    async def _init_browser_context(self):
        """
        实现平台登录操作,如扫码、验证码登录等
        """
        async with async_playwright() as playwright:
            self.browser = await playwright.chromium.connect_over_cdp(self.cdp_endpoint)
            self.context = self.browser.contexts[0]  # 复用第一个上下文