2

我正在尝试在网页上查找国家/城市。所以我使用了地理。但它不能正常工作。注意:给定网站包含美国所有州网站 = http://state.1keydata.com/

import geograpy
url='http://state.1keydata.com/'
place=geograpy.get_place_context(url=url)
print place.countries  #[]
print place.cities #[]

我已经安装了所有必需的软件包,例如 georapy、nltk(all) 我正在使用 Anaconda。

如果我错了,请指导。

先感谢您 :)

4

3 回答 3

2

您要测试的页面在现场,证书不正确,这会导致我没有尝试解决的不同问题。相反,我正在使用: https ://en.wikipedia.org/wiki/US_state

作为例子。

作为 geograpy3 的提交者以重现您的问题,我向最新的 geograpy3 https://github.com/somnathrakshit/geograpy3/blob/master/tests/test_extractor.py添加了一个测试:

def testStackoverflow43322567(self):
        '''
        see https://stackoverflow.com/questions/43322567/python-geograpy-is-not-finding-cities-in-usa
        '''
        url='https://en.wikipedia.org/wiki/U.S._state'
        e=Extractor(url=url)
        places=e.find_geoEntities()
        self.check(places,['Alabama','Virginia','New York'])
于 2020-09-09T12:03:06.110 回答
0

我发现手动重新安装所有必需的软件包,以及对地理库文件进行调整就可以了。检查此以获取更多详细信息。

  1. lxml
  2. 美丽的汤
  3. 枕头

接下来,我从命令行运行python nltk.download()命令

完成这些步骤后,我收到另一条错误消息:

Traceback (most recent call last):
  File "ExtractLocation_geograpy.py", line 5, in <module>
    places = geograpy.get_place_context(text = text1)
  File "C:\Users\Avardhan\Documents\CVS_POC\.env\lib\site-packages\geograpy\__init__.py", line 11, in get_place_context
    pc.set_cities()
  File "C:\Users\Avardhan\Documents\CVS_POC\.env\lib\site-packages\geograpy\places.py", line 174, in set_cities
    self.country_cities[country.name] = []

通过替换country.namecountry_name我终于能够获得所需的输出。

于 2017-10-23T19:40:10.560 回答
0

您测试的页面不包含任何城市或国家/地区名称,因此您得到空结果也就不足为奇了。

于 2017-04-10T12:53:31.363 回答