6

I am trying to get addresses from a web page for mapping purposes. I know I could copy and paste the addresses into an Excel file and geocode them but I was wondering if there was any faster way to get the address from a web page and create a point location file?

3
  • It all depends on how the addresses are formatted on said web page, but yes parsing addressing into a .csv and then geocoding is quite possible.
    – MLowry
    Jan 23, 2012 at 19:15
  • 2
    It sounds like you are talking about web scraping. If that is the case, which isn't really a GIS question, consider asking the question over at StackOverflow, or searching their tags screen-scraping and web-scraping. Jan 23, 2012 at 19:41
  • as above, but it's fairly easy to write a small app that looks at a specific part of a web page and disemintaes the information.
    – Hairy
    Jan 24, 2012 at 12:15

1 Answer 1

11

This should get you started. Python and the BeautifulSoup module to the rescue. The code below will print out a list of the 26 addresses on that webpage. I used Firebug in Firefox to look at the page source, which told me that the cell width was 37%. I gambled that those cells were maybe the only ones at 37% width, and was right. You should be able to feed the list of addresses you get into a online geocoder and get point locations.

enter image description here

import BeautifulSoup as bs
import urllib2

url = 'http://www.phillypal.com/pal_locations.php'

response = urllib2.urlopen(url)
html = response.read()
soup = bs.BeautifulSoup(html)

addresses = soup.findAll('td', {'width':'37%'})

print len(addresses)

for address in addresses:
    print address.find(text=True)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.