python+playwright 学习-77 playwright 发送接口请求APIRequestContext

前言

每个Playwright浏览器上下文都有与其关联的APIRequestContext实例,该实例与浏览器上下文共享cookie存储,可以通过browser_context.request或page.request访问。也可以通过调用api_request.new_context()手动创建一个新的APIRequest上下文实例。

通过浏览器发请求

可以通过browser_context.request或page.request发送接口请求,该实例与浏览器上下文共享cookie存储。

from playwright.sync_api import sync_playwright, expect
# 上海悠悠 wx:283340479
# blog:https://www.cnblogs.com/yoyoketang/


REPO = "test-repo-1"
USER = "github-username"
API_TOKEN = "xx1122"


with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)
    context = browser.new_context(base_url="https://api.github.com")
    # context 上下文创建 request 请求对象
    api_request_context = context.request
    page = context.new_page()

    # 访问浏览器页面
    

你可能感兴趣的:(playwright,python,学习,开发语言)