0

我需要能够更改 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

将标题设置为页面或上下文会产生相同的错误。可以用剧作家设置主机头吗?

4

1 回答 1

0

Chromium 不允许您覆盖Host标头。我认为这是因为Host浏览器内部管理的东西。来源

为什么要修改此标头?

于 2021-08-05T14:13:25.747 回答