使用Selenium(3.4.3)在python中为Geckodriver(v.1.18)设置用户代理适用于一个站点,但对另一个站点失败。
user_agent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0"
#self.base_url = "http://whatsmyuseragent.com/"
self.base_url = "http://www.google.com"
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
firefox_profile.set_preference("general.useragent.override", user_agent)
self.driver = webdriver.Firefox(executable_path='D:\Drivers\geckodriver', firefox_profile=firefox_profile)
self.driver.get(self.base_url)
agent = self.driver.execute_script("return navigator.userAgent")
print(agent)
来自Google网站的错误消息是:
The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.