我需要从网站中提取所有城市名称。我在以前的项目中使用了beautifulSoup 和RE,但在这个网站上,城市名称是常规文本的一部分,没有特定的格式。我找到了满足我要求的地理包(https://pypi.python.org/pypi/geograpy/0.3.7 )。
Geograpy 使用 nltk 包。我为 nltk 安装了所有模型和包,但它一直抛出这个错误:
>>> import geograpy
>>> places = geograpy.get_place_context(url="http://www.state.gov/misc/list/")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\geograpy\__init__.py", line 6, in get_place_context
e.find_entities()
File "C:\Python27\lib\site-packages\geograpy\extraction.py", line 31, in find_entities
if (ne.node == 'GPE' or ne.node == 'PERSON') and ne[0][1] == 'NNP':
File "C:\Python27\lib\site-packages\nltk\tree.py", line 198, in _get_node
raise NotImplementedError("Use label() to access a nod label.")
NotImplementedError: Use label() to access a node label.
任何帮助,将不胜感激