[英]Python selenium with chrome webdriver - change user agent
[英]Change User Agent client hints for Selenium webdriver
我一直在通过以下方式更改用户代理:
chrome_options.add_argument("user-agent=" + USER_AGENT)
我注意到 Chrome 有额外的用户代理客户端提示标头,例如Sec-CH-UA-Platform
、 Sec-CH-UA
等,如在此处看到和测试的那样。
我想更改这些客户端提示(特别是Sec-CH-UA-Platform
)而不使用使用 Selenium 的扩展。这是否可能类似于用户代理的更改方式?
这可以使用Selenium-Profiles 。
目前它具有以下特点:
driver.requests.fetch(url, options)
( 语法)发出单个POST 、GET 或其他请求并允许更改以下内容:
{
"options": {
"browser": {
"sandbox": true,
"window_size": {"x":1024,"y":648},
"headless": false,
"load_images": true,
"incognito": true,
"app": false,
"gpu": false,
"proxy": null,
"proxy_method": null
},
"extensions": {
"extension_paths": [],
"auth_proxy": {"host":"host","port":9000,"username":"user", "password":"password"}
},
"option_args": ["--my-arg1", "..."],
"capabilities": [],
"adb": false,
"adb_package": "com.android.chrome",
"use_running_app": true
},
"cdp": {
"browser": {
"pointer_as_touch": false,
"darkmode": false,
"mobile": true
},
"touch": true,
"maxtouchpoints": 5,
"cdp_args": [],
"emulation": {"mobile":true,"width": 384, "height": 700, "deviceScaleFactor": 10,
"screenOrientation": {"type": "portrait-primary", "angle": 0}},
"useragent": {
"platform": "Linux aarch64",
"acceptLanguage":"en-US",
"userAgent": "Mozilla/5.0 (Linux; Android 11; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile Safari/537.36",
"userAgentMetadata": {
"brands": [{"brand": "Google Chrome", "version": "105"}, {"brand": "Not)A;Brand", "version": "8"},
{"brand": "Chromium", "version": "105"}],
"fullVersionList": [{"brand": "Google Chrome", "version": "105.0.5195.136"},
{"brand": "Not)A;Brand", "version": "8.0.0.0"},
{"brand": "Chromium", "version": "105.0.5195.136"}],
"fullVersion": "105.0.5195.136",
"platform": "Android",
"platformVersion": "11.0.0",
"architecture": "",
"model": "HD1913",
"mobile": true,
"bitness": "",
"wow64": false}
}}
}
所有这些选项都是可选的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.