Python urllib Examples

From PeformIQ Upgrade
Revision as of 10:33, 23 May 2008 by PeterHarding (talk | contribs) (New page: =Scripts= <pre> import urllib import urllib2 from xml.dom import minidom user_address = '1600 Pennsylvania Avenue NW Washington, DC 20500' url = 'http://xxxxxxxxx.xx.xxxxxx' #geocoding s...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Scripts

import urllib
import urllib2
from xml.dom import minidom

user_address = '1600 Pennsylvania Avenue NW Washington, DC 20500'
url = 'http://xxxxxxxxx.xx.xxxxxx' #geocoding servlet url
values = {'address': user_address} #

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
xmlResults = response.read()

xmldoc = minidom.parseString(xmlResults)
places = xmldoc.getElementsByTagName('Placemark')

nameTag = places[0].getElementsByTagName('name')
print nameTag[0].firstChild.wholeText