iamchellapandi
iamchellapandi

Reputation: 21

Python Geograpy is not finding Cities In USA

I'm trying to find Countries/Cities on the webpage. So I used Geograpy. but it is Not working properly. Note: given website contains All the States in United States Website = http://state.1keydata.com/

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

I have installed all the required packages like georapy,nltk(all) I am using Anaconda.

Please guide if I'm wrong.

Thank you in advance :)

Upvotes: 2

Views: 880

Answers (3)

Wolfgang Fahl
Wolfgang Fahl

Reputation: 15769

The page you would like to test is on site with an improper certificate which leads to a different problem i didn't try to solve. Instead i am using: https://en.wikipedia.org/wiki/U.S._state

as the example.

As a committer of geograpy3 to reproduce your issue i added a test to the most recent 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'])

Upvotes: 2

avcodes
avcodes

Reputation: 51

I found that re-installing all required packages manually, as well as adding a tweak to the geography library files did the trick. Check this for more details.

  1. lxml
  2. beautifulsoup
  3. pillow

Next, I ran the command python nltk.download() from the command line

After doing these steps, I got another error message:

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] = []

By replacing country.name with country_name, I was able to finally get the required output.

Upvotes: 0

alexis
alexis

Reputation: 50200

The page you tested on doesn't contain any city or country names, so it's not surprising that you get empty results.

Upvotes: 0

Related Questions