Python Playwright로 Edge 브라우저 제어하기

Python에서 Playwright를 사용하면 Chromium 기반의 Edge 브라우저를 다양한 방식으로 제어할 수 있습니다.
이 글에서는 브라우저를 실행하거나 연결하는 대표적인 방법 세 가지를 정리했습니다.


1. launch – 새 브라우저 실행

async with async_playwright() as p:
    browser = await p.chromium.launch(
        channel="msedge",
        headless=False,
        args=[
            "--remote-debugging-port=9222",  # 선택 사항
            "--start-maximized",
            "--disable-infobars",
        ],
    )
    context = await browser.new_context(no_viewport=True)
    page = await context.new_page()
  • 완전히 새로운 브라우저 프로세스를 실행합니다.
  • --remote-debugging-port는 Playwright 단독 사용 시 필요하지 않지만, Puppeteer나 DevTools 같은 다른 툴과 병행할 때 유용합니다.
  • 항상 깨끗한 환경에서 시작할 수 있다는 장점이 있습니다.

2. connect_over_cdp – 실행 중인 브라우저에 접속

async with async_playwright() as p:
    browser = await p.chromium.connect_over_cdp("http://127.0.0.1:9222")
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else await context.new_page()
  • 이미 실행 중인 브라우저에 연결해 제어할 수 있습니다.
  • 이 방식을 쓰려면 브라우저를 --remote-debugging-port=9222 옵션과 함께 실행해야 합니다.
  • 기존에 열려 있던 탭, 세션 등을 그대로 활용할 수 있습니다.

3. launch_persistent_context – 프로필 기반 실행

async with async_playwright() as p:
    context = await p.chromium.launch_persistent_context(
        channel="msedge",
        user_data_dir=data_dir,
        headless=False,
        args=[
            "--start-maximized",
            "--disable-infobars",
            "--test-type"
        ],
        ignore_https_errors=True,
        no_viewport=True,
    )

    page = context.pages[0] if context.pages else await context.new_page()
  • user_data_dir을 지정해 특정 프로필 디렉토리를 사용합니다.
  • 쿠키, 로그인 상태, 확장 프로그램 등을 유지하면서 자동화를 실행할 수 있습니다.
  • 이 방식에서는 remote-debugging-port 옵션이 필요하지 않습니다.

Comments

Tips & Tech

Linux Apache에서 GPTBot·Amazonbot·AhrefsBot의 게시판 이미…
Others Midjourney, DALL·E, ChatGPT에서 Y2K 파스텔 UI 프롬프…
Linux Cloudflare R2 자동 업로드 구성하기. 특정 폴더에 파일…
WordPress 워드프레스 7.0 관리자 링크 색상 변경 후 이전 색상으…
WordPress 캐시 환경에서 AJAX 댓글(코멘트) 분리로 서버 응답시간…
Linux 아파치 일반 계정 파일 접근 권한 설정과 mod-ruid2 적…
Delphi Delphi IDE 메인 폼 안열림 dproj 설정으로 해결
Dev tips VSCode 한국어 설정법, Configure Display Language로 U…
Others RustDesk 자체 서버 구축으로 공용 서버 로그인 문제 해…
Linux Dante SOCKS5 프록시 서버 구축 및 설정
Windows 윈도우 실행파일(exe) 서비스 등록 자동화 쉽게 하는 방…
Others CLIProxyAPI Windows 설치 가이드
WordPress 그누보드7 데이터를 WordPress WXR로 변환하기
Others Ollama 설치 경로 C드라이브 고정 문제 해결 및 드라이…
Dev tips Apache Access Log 기반 도메인별 방문자 카운터 구현
Windows ZImage AI 이미지 생성 환경 구축 방법
Windows 파일 복사 후 실행 배치파일 - 에러 감지 포함
Dev tips 네이버 검색 Open API
Dev tips 네이버 검색광고 키워드 도구 API 검색
Dev tips MariaDB column_stats 테이블 오류 해결 방법
Dev tips PHP-FPM 에러 로그 실시간 모니터링
Windows 윈도우11 업데이트 후 네트워크 드라이브 접근 불가 문…
Dev tips 다국어 번역 함수 구현 방법
WordPress "치명적인 오류가 발생했습니다" 디버깅 가이드
Linux Apache 웹 로그 분석하기 – awk와 GoAccess 활용
Windows 윈도11 강제업데이트 피하고 윈도10 계속 쓰기
Linux PHP 파일 업로드 용량 늘리기
Dev tips 애드센스 충돌 문제 해결하기
Views Python Python Playwright로 Edge 브라우저 제어하기
Delphi TDirectory.Delete 대신 CMD 으로 폴더 삭제