Is anyone in the UK doing postcode lookup using the Royal Mail website from XOJO.
My postcode lookup needs are so small that I don’t want to commit to an expensive API - i.e. I would be lucky to do 50 lookups a year, never mind a day so the royal mail site seems the way to go and T&C’s allow for personal use. I would like to post to the site a postcode and recover the list of addresses it presents. Is this even possible in the background? The list could then be parsed to fill a few fields in my system (a little less crude than cut and paste).
Web scraping can be unreliable and possibly violate certain terms of service.
Here’s a quick and dirty example using a non-Royal Mail API found at https://getaddress.io/ which lets you make 20 free API calls a day. I used a mix of old httpsocket and new dictionary because I find those easier to use for simple projects:
[code]dim apikey, postalcode, url, tmp1, tmp2(), addr as text
dim ret as string
dim https as new HTTPSecureSocket
dim d as new xojo.Core.Dictionary
dim a() as auto
dim i, j as integer
ret = https.get(url, 30).defineencoding(encodings.UTF8)
d = xojo.data.ParseJSON(ret.ToText)
a = d.value(“Addresses”)
for i = 0 to a.Ubound
tmp1 = a(i)
tmp2 = tmp1.Split(",")
for j = 0 to tmp2.Ubound
addr = tmp2(j).trim
if j = 0 then
tmp1 = addr
elseif addr <> "" then
tmp1 = tmp1 + ", " +addr
end if
next
PopupMenu1.AddRow(tmp1)