我正在尝试在网页上查找国家/城市。所以我用了Geograpy。但它不能正常工作。注:给定网站包含美国所有国家的网站= 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。
如果我说错了,请指点一下。
提前感谢您:)
发布于 2020-09-09 20:03:06
您想要测试的页面在站点上使用了不正确的证书,这导致了另一个我没有尝试解决的问题。相反,我使用的是:https://en.wikipedia.org/wiki/U.S._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'])
发布于 2017-04-10 20:53:31
您测试的页面不包含任何城市或国家名称,因此得到空结果也就不足为奇了。
发布于 2017-10-24 03:40:11
我发现,手动重新安装所有必需的软件包,以及向地理库文件添加一个调整就可以做到这一点。Check this获取更多详细信息。
接下来,我从命令行运行命令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_name
替换country.name
,我最终能够获得所需的输出。
https://stackoverflow.com/questions/43322567
复制相似问题