In Selenium, it is possible to specify a custom user agent when launching Chrome to simulate different browsing devices or environments. To achieve this, you need to modify the Options object before creating the ChromeDriver instance.
The provided code has a few issues:
Here's a corrected version of your code:
<code class="python">from selenium.webdriver.chrome.options import ChromeOptions from selenium import webdriver opts = ChromeOptions() opts.add_argument("--user-agent=Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 640 XL LTE) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10166") driver = webdriver.Chrome(chrome_options=opts, executable_path="PATH_TO_CHROME_DRIVER") driver.get("https://www.bing.com/")</code>
The above is the detailed content of How to Change User Agent in Google Chrome with Selenium?. For more information, please follow other related articles on the PHP Chinese website!