如何从“位置”键的值中获取国家?

2024-04-26 02:44:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试添加一个名为Country的新键。我的主要问题是把地点转换成国家。Stackoverflow的用户可以写入所有内容,但它没有格式。我试过地质学,但它没有发现一些国家的RussiaTokyo作为一个国家。你知道吗

第二个问题是geopy不允许太多的访问或请求。我有大约800万用户。你知道吗

该代码只是一个编辑版本:

def geopytesting(testing, user):
    from geopy import Nominatim

    try:
        geolocator = Nominatim()
        location2 = geolocator.geocode(testing)
        print(location2.address)
    except BaseException:
        print("Error")

geopytesting("Russia",None)
geopytesting("Hamburg",None)
geopytesting("Madrid",None)
geopytesting("Omaha",None)
geopytesting("Berlin",None)
geopytesting("Schleswig-Holzstein",None)
geopytesting("Asyż",None)
geopytesting("",None)
geopytesting("Tilted Tower",None)

希望你们能帮我。我真的尝试了很多事情,但我还没有看到一个处理这个具体问题的帖子。 要么它检测到一些国家,要么我被踢出去,因为我提出了很多要求。你知道吗

致以最诚挚的问候 乔希


Tags: 用户none国家stackoverflowtestingcountryprint地点