Difference between revisions of "Python urllib Examples"

From PeformIQ Upgrade
Jump to navigation Jump to search
m
Line 9: Line 9:
url          = 'http://xxxxxxxxx.xx.xxxxxx'  # geocoding servlet url
url          = 'http://xxxxxxxxx.xx.xxxxxx'  # geocoding servlet url
values        = {'address': user_address}
values        = {'address': user_address}
data          = urllib.urlencode(values)
data          = urllib.urlencode(values)


req          = urllib2.Request(url, data)
req          = urllib2.Request(url, data)
response      = urllib2.urlopen(req)
response      = urllib2.urlopen(req)



Revision as of 10:35, 23 May 2008

Scripts

import urllib
import urllib2
from xml.dom import minidom

user_address  = 'nnn Collins Street, Victoria 3000'
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