from playwright.sync_api import Playwright, sync_playwright, expect def run(playwright: Playwright) -> None: user_data_dir = "/Users/kaka/Library/Application Support/Google/Chrome" # user_data_dir = "/Users/kaka/chrome" args = [ '--disable-blink-features=AutomationControlled', f"--disable-extensions", f"--disable-popup-blocking", f"--ignore-certificate-errors", f"--disable-plugins-discovery", f'--no-first-run', f'--no-service-autorun', f'--no-default-browser-check', # f'--no-startup-window', f'--disable-dev-shm-usage', # f"--disable-extensions-except={cookie_extension},{path_to_extension}", ] headless = False context = playwright.chromium.launch_persistent_context( user_data_dir, channel="chrome", device_scale_factor=1, devtools=False, headless=False, args=args ) browser = context.browser page = context.new_page() page.set_default_timeout(10000) # 跳到登录页面 page.goto("https://cnlogin.cainiao.com/login?appKey=12497914&istb=true&redirectURL=https%3A%2F%2Fmerchant.finance.cainiao.com%2Ffunds%2Findex.htm%3Ftbpm%3D3&showae=true&showin=false&showdd=false&tbUserName=&sub=&type=ML&domain=&lang=&isNewLogin=&targetAccount=&meta=&isEnterprise=&isQTb=false&isCnSSOTb=false") page.wait_for_timeout(5000) # Usename: fundpark; Password: Fundpark2019@ try: username = page.frame_locator("#J_taobao iframe").locator('#fm-login-id') username.click() username.fill('cainiao_account') page.wait_for_timeout(1000) except Exception as e: print(f"账号名/邮箱/手机号->Exception:{e}") pass try: userpass = page.frame_locator("#J_taobao iframe").locator('#fm-login-password') userpass.click() userpass.fill('cainiao_password') page.wait_for_timeout(1000) except Exception as e: print(f"请输入登录密码->Exception:{e}") pass # 获取拖动按钮位置并拖动 try: drop_button = page.frame_locator("#J_taobao iframe").frame_locator("#baxia-dialog-content").locator("#nc_1_n1z") box = drop_button.bounding_box() page.mouse.move(box['x'] + box['width'] / 2, box['y'] + box['height'] / 2) page.mouse.down() mov_x = box['x'] + box['width'] / 2 + 260 page.mouse.move(mov_x, box['y'] + box['height'] / 2) page.mouse.up() page.wait_for_timeout(5000) except Exception as e: print(f"获取拖动按钮位置并拖动->Exception:{e}") pass # 登录按钮 try: # page.frame_locator("#J_taobao iframe").locator(".fm-submit").click() page.frame_locator("#J_taobao iframe").locator(".fm-submit").click() page.wait_for_timeout(5000) except Exception as e: print(f"登录按钮->Exception:{e}") pass # 快速进入 try: # page.frame_locator("#J_taobao iframe").locator(".fm-submit").click() # page.frame_locator("#J_taobao iframe").get_by_role("button", name="快速进入") quick_entry = page.frame_locator("#J_taobao iframe").locator(".fm-submit") quick_entry.click() quick_entry.click() page.wait_for_timeout(5000) except Exception as e: print(f"快速进入->Exception:{e}") pass page.wait_for_timeout(10000000) context.close() browser.close() def on_response(response): if (response.url == "https://member.cainiao.com/login2.htm?redirect_url=https%3A%2F%2Fmerchant.finance.cainiao.com%2Ffunds%2Findex.htm%3Ftbpm%3D3"): print(response) with sync_playwright() as playwright: run(playwright)
标签:box,Exception,playwright,--,菜鸟,frame,locator,后台,page From: https://www.cnblogs.com/kaka0318/p/17042993.html