python版本的playwright如何使用代理

 

 

from playwright.sync_api import Playwright, sync_playwright

with sync_playwright() as playwright:
    browser = playwright.chromium.launch()
    proxy_server = 'http://my-proxy-server.com:8080'
    context = browser.new_context(proxy={
        'server': proxy_server,
        'username': 'my-username', # 如果需要身份验证,可以通过这里指定用户名和密码
        'password': 'my-password'
    })

    page = context.new_page()
    page.goto('http://example.com')

    browser.close()

 

posted @ 2023-06-26 12:38  AngDH  阅读(804)  评论(0编辑  收藏  举报