Difference between revisions of "Python urllib Examples"
Jump to navigation
Jump to search
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...) |
PeterHarding (talk | contribs) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
from xml.dom import minidom | from xml.dom import minidom | ||
user_address = ' | user_address = 'NNN Collins Street, Victoria 3000' | ||
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) | |||
req = urllib2.Request(url, data) | |||
req = urllib2.Request(url, data) | response = urllib2.urlopen(req) | ||
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 | |||
</pre> | </pre> | ||
[[Category:Python]] | [[Category:Python]] | ||
[[Category:urllib]] | [[Category:Python httplib]] | ||
[[Category:Python urllib]] | |||
[[Category:Examples]] | |||
[[Category:Internet]] | |||
[[Category:XML]] | [[Category:XML]] |
Latest revision as of 15:04, 1 August 2015
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