我需要能够更改 url 的主机头。我尝试设置额外的标题,但我不断收到无效的参数错误。
from playwright.sync_api import sync_playwright
def get_title():
with sync_playwright() as playwright:
browser = playwright.chromium.launch(headless=True)
context = browser.new_context(
user_agent="testing",
)
context.set_extra_http_headers({"host": "example.com"})
page = context.new_page()
page.goto(url="http://111.222.333.444", wait_until="domcontentloaded")
title = page.inner_html(selector="title")
context.close()
browser.close()
return title
将标题设置为页面或上下文会产生相同的错误。可以用剧作家设置主机头吗?