【问题标题】:how to set random fake geolocation in selenium python with spasific country如何在特定国家/地区的 selenium python 中设置随机假位置
【发布时间】:2021-11-29 04:06:18
【问题描述】:

我正在尝试添加来自美国或英国等有效国家/地区的随机假 geolocation

也许这可以帮助pip install geopy

【问题讨论】:

  • 使用代理或在使用美国 IP 地址的 google colab 上运行 Selenium
  • 已经使用来自同一个国家的代理,为什么我需要使用多个位置而不是代理给我的位置

标签: python selenium random geolocation faker


【解决方案1】:

将查询地理定位到地址和坐标:

from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="specify_your_app_name_here")
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)

Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ...

print((location.latitude, location.longitude))
(40.7410861, -73.9896297241625)

print(location.raw)
{'place_id': '9167009604', 'type': 'attraction', ...}

找到一组坐标对应的地址:

from geopy.geocoders import Nominatim

geolocator = Nominatim(user_agent="specify_your_app_name_here")

location = geolocator.reverse("52.509669, 13.376294")

print(location.address)
Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union

print((location.latitude, location.longitude))
(52.5094982, 13.3765983)

print(location.raw)
{'place_id': '654513', 'osm_type': 'node', ...}

https://geopy.readthedocs.io/en/stable/

【讨论】:

    猜你喜欢
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2023-03-21
    • 2019-04-16
    • 2012-01-21
    • 1970-01-01
    相关资源
    最近更新 更多