如何在Chrome for Selenium中设置伪造的GeoLocation [英] How to set a fake GeoLocation in Chrome for Selenium

查看:54
本文介绍了如何在Chrome for Selenium中设置伪造的GeoLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Chrome for Selenium中设置伪地理位置?(尝试使用locationcontext和下面的Javascript,但似乎不起作用)

How to set a Fake GeoLocation in Chrome for Selenium? (Tried using locationcontext and also Javascript below but it doesnt seem to work)

我在这里尝试过此解决方案- Chrome自动化中的伪地理定位,但它没有似乎不起作用

I have tried the solution here - fake Geolocation in chrome automation but it doesn't seem to work

推荐答案

您可以使用Chrome Devtools协议(cdp):

You can use the Chrome Devtools Protocol (cdp):

params = {
    "latitude": 50.1109,
    "longitude": 8.6821,
    "accuracy": 100
}

self.driver = webdriver.Chrome()
self.driver.execute_cdp_cmd("Page.setGeolocationOverride", params)
self.driver.get('https://www.google.com/maps')

这篇关于如何在Chrome for Selenium中设置伪造的GeoLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆