gpt4 book ai didi

java - Selenium - 移动仿真 - 如何在自动化仿真器时将用户代理添加到 Chrome 选项?

转载 作者:行者123 更新时间:2023-12-05 05:14:48 24 4
gpt4 key购买 nike

以下是我添加的功能。我收到 Google reCAPTCHA在我的网站上,可以通过添加用户代理来侵入。

但即使在添加了用户代理之后,我仍然得到验证码。还有其他方法可以添加吗?

Map<String, String> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceName", "Pixel 2");

Map<String, Object> chromeOptions = new HashMap<>();
chromeOptions.put("mobileEmulation", mobileEmulation);

chromeOptions.put("args",
Arrays.asList("disable-bundled-ppapi-flash",
"disable-extensions",
"profile-directory=Default",
"disable-plugins-discovery",
"--user-agent=" + userAgent));

ChromeOptions co = new ChromeOptions();
co.addArguments("mobileEmulation="+mobileEmulation);

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY,chromeOptions);

System.setProperty("webdriver.chrome.driver", RunConfig.CHROME_DRIVER_EXE);

driver = new ChromeDriver(capabilities);

最佳答案

您可以在 Chrome 网络浏览器中使用以下配置进行移动仿真:

Map<String, Object> deviceMetrics = new HashMap<>();
deviceMetrics.put("width", 1078);
deviceMetrics.put("height", 924);
deviceMetrics.put("pixelRatio", 3.0);
Map<String, Object> mobileEmulation = new HashMap<>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", "Mozilla/5.0 (Linux; Android 8.0.0;" +
"Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML,
like Gecko) " +
"Chrome/67.0.3396.99 Mobile Safari/537.36");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
driver = new ChromeDriver(chromeOptions);

而不是添加要使用的参数 setExpermentalOption

// co.addArguments("mobileEmulation=" + mobileEmulation);
co.setExperimentalOption("mobileEmulation", mobileEmulation);

关于java - Selenium - 移动仿真 - 如何在自动化仿真器时将用户代理添加到 Chrome 选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52273722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com