2017-04-10 44 views
0

我正在嘗試在網頁上找到國家/城市。所以我使用了Geograpy。 但它不能正常工作。 注:給定網站包含的所有國美 網站= http://state.1keydata.com/Python Geograpy在美國找不到城市

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

我已經安裝了所有必需的包像georapy,NLTK(全部) 我使用的蟒蛇。

請指導如果我錯了。

預先感謝您:)

+1

'不能正常工作'是一個相對術語。如果詳細闡述你面臨的問題,這對你會有好處。 –

+0

我將編輯問題 – iamchellapandi

+2

您是否需要指向詳細信息頁面?頁面http://state.1keydata.com/沒有列出國家和citites。只是說明。所以如果不知道確切的模塊,我期望得到一個空的結果。 – Flurin

回答

0

你測試的不包含任何城市或國家名稱的頁面,所以這並不奇怪,你得到空的結果。

+0

請幫我找到該頁面的狀態 – iamchellapandi

+0

試試'place.regions'或'place.other'。剛剛閱讀項目頁面... – alexis

+0

我也試過。它給出了空的列表。 – iamchellapandi

0

我發現手動重新安裝所有必需的軟件包,以及爲地理庫文件添加一個調整的技巧。 Check this瞭解更多詳情。

  1. LXML
  2. beautifulsoup
  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_name代替country.name,我終於能夠獲得所需的輸出。