[common] allow overriding 'user-agent' when 'browser' is used (#7647)

This commit is contained in:
Mike Fährmann
2025-06-10 22:03:15 +02:00
parent 8e698d1a64
commit b4aed5e2c9
2 changed files with 10 additions and 14 deletions

View File

@@ -673,11 +673,6 @@ Description
Setting this value to ``"browser"`` will try to automatically detect
and use the ``User-Agent`` header of the system's default browser.
Note:
This option has *no* effect if
`extractor.browser <extractor.*.browser_>`__
is enabled.
extractor.*.browser
-------------------

View File

@@ -419,15 +419,7 @@ class Extractor():
ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1)
ssl_ciphers = SSL_CIPHERS[browser]
else:
useragent = self.config("user-agent")
if useragent is None or useragent == "auto":
useragent = self.useragent
elif useragent == "browser":
useragent = _browser_useragent()
elif self.useragent is not Extractor.useragent and \
useragent is config.get(("extractor",), "user-agent"):
useragent = self.useragent
headers["User-Agent"] = useragent
headers["User-Agent"] = self.useragent
headers["Accept"] = "*/*"
headers["Accept-Language"] = "en-US,en;q=0.5"
@@ -449,6 +441,15 @@ class Extractor():
elif self.root:
headers["Referer"] = self.root + "/"
custom_ua = self.config("user-agent")
if custom_ua is None or custom_ua == "auto":
pass
elif custom_ua == "browser":
headers["User-Agent"] = _browser_useragent()
elif self.useragent is Extractor.useragent or \
custom_ua is not config.get(("extractor",), "user-agent"):
headers["User-Agent"] = custom_ua
custom_headers = self.config("headers")
if custom_headers:
if isinstance(custom_headers, str):