What python libraries can tell me approximate location and time zone given an IP address?

后端 未结 13 725
借酒劲吻你
借酒劲吻你 2020-11-28 03:31

Looking to implement better geo-location with Python.

13条回答
  •  情书的邮戳
    2020-11-28 04:27

    I think freegeip is a good option. Below is the Python 3.4.2 code for getting location and time zone.

    >>> import requests
    >>> ip = '141.70.111.66'   
    >>> url = 'http://freegeoip.net/json/'+ip
    >>> r = requests.get(url)
    >>> js = r.json()
    >>> js['country_code']
    'DE'
    >>> js['country_name']
    'Germany'
    >>> js['time_zone']
    'Europe/Berlin'
    

提交回复
热议问题