UK Postcode Lookup

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).

The website is here;

http://www.postoffice.co.uk/postcode-finder

An example postcode sn13ex produces 6 ‘possibles’.

Can these be ‘grabbed’ and added to a popup menu from the returned ‘popup menu’?

I have done simple sock stuff with http post, but nothing like this so I don’t know where to start :frowning:

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

https.Secure = True
https.ConnectionType = https.TLSv12

apikey = “your-api-key”
postalcode = “sn13ex”

url = “https://api.getAddress.io/v2/uk/” + postalcode + “?api-key=” + apikey

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)

next[/code]

I have an SQLite database with all postcodes up until the number just after the space i.e. it gives the town, county and country, but not the street.

Thanks both, https://getaddress.io/ offers good value for my needs an the example works flawlessly.

thanks i got the code working for my application… thanks guy… for the getaddress.io thingy

i just duplicate my curl and json thingy for UKVehicleData and modify for the GetAddress.io and it work great