2
url = 'http://www.zillow.com/homedetails/3728-Balcary-Bay-Champaign-IL-61822/89057727_zpid/'
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

info = soup.findAll('span',{'itemtype':'http://schema.org/GeoCoordinates'}) #this tag + class combination found 4 matches, 4th one was the required one, just selecting that here
for form in info:
        b= form.find('meta')['content']
print b

This is the snapshot of the code i am using to get the latitude and longitude information from Zillow. I can pin point the code where the latitude and longitude information is stored using span and itemtype. The place where I am parsing this data from has a code similar to the one below:

<span itemprop="geo" itemscope="" itemtype="http://schema.org/GeoCoordinates">
<meta content="40.12938" itemprop="latitude">
<meta content="-88.30766" itemprop="longitude">
</span>

I am able to get the latitude information but unable to get the longitude information. Can someone help me in getting this information?

Output of the code:

>>> ================================ RESTART ================================
>>> 
40.12938
>>> 

Intended output:

>>> ================================ RESTART ================================
>>> 
40.12938 -88.30766
>>> 

1 Answer 1

1

the form.find() finds the first result which is <meta content="40.12938" itemprop="latitude"> but instead use the form.find_all() method to return all the results and then you can add them to a list using a list comprehension as depicted below:

url = 'http://www.zillow.com/homedetails/3728-Balcary-Bay-Champaign-IL-61822/89057727_zpid/'
page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

info = soup.findAll('span',{'itemtype':'http://schema.org/GeoCoordinates'}) #this tag + class combination found 4 matches, 4th one was the required one, just selecting that here
cordinates = [i['content'] for i in info[0].find_all('meta')]

print cordinates

it would produce:

[u'40.12938', u'-88.30766']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.