Getting UK postcode using address (1 Viewer)

Владимир

New member
Local time
Today, 19:29
Joined
May 30, 2020
Messages
12
Hello everybody!
And I apologize for my poor English.

In my database there are fields on the form: House Number, Street Address, Street Address 2 and City. (Street Address 2 - this is an additional field).
I would like to get the postcode of this address using webscraping.

I know how to find and get this data from a web page.
But I don’t know how I can make the web page find the postcode data of my address.

I would like to know how to open a web page with the data of my address.
For example, for the inverse task (getting the address from postcode), the postcode value is added to the site address bar


How to do something similar for an address (can be on another site)?
 

Владимир

New member
Local time
Today, 19:29
Joined
May 30, 2020
Messages
12
All I want is the ability to go to a page on a site using the address, which would be scraping postcode

i.e., ".../ some website / City_Street Address_Street Address 2_House Number", for example
 

Владимир

New member
Local time
Today, 19:29
Joined
May 30, 2020
Messages
12
Thank Gasman.
I have already seen these sites, but I don’t know how to use the WinHttpRequest to go to the page with my postcode.
 

isladogs

MVP / VIP
Local time
Today, 17:29
Joined
Jan 14, 2017
Messages
18,186
Hi and welcome to AWF.
I've absolutely no idea how to pronounce your user name. Where are you from?

For info I moved your thread from Sample databases which is a moderated area and not intended for questions.

The UK postcodes and address databases are available under licence from the Royal Mail and, with few exceptions, you will need to pay for that data, either directly from Royal Mail or indirectly from a reseller.

The 192.com site is an exception as its free. It works well from small scale use but is intended mainly for getting addresses from postcodes.
I have a free example database that makes use of this feature:

I also have a commercial app UK Postal Address Finder which has many features including the ability to get the full address including postcode from a partial address. The screenshot gives you an idea of how it works
1590863703105.png


Obviously entering something like Hill Street gives a lot of results (max 100).
However entering a more precise address such as 3 Hill Street, York will give a unique result.

But to repeat (and following on from Gasman's comments), it is highly unlikely you will get this info without paying for it.
If you want to look at my app, a time limited evaluation version is available.
 

Владимир

New member
Local time
Today, 19:29
Joined
May 30, 2020
Messages
12
Hello isladogs
I am from the Republic of Belarus. It is a small country between Poland and Russia.

I have already seen your posts in similar topics.
You always promote your database. ):

As I already wrote, I do not need to find out the address. I already know the address. I want to find out the postcode for this address. Also, I do not need a ready-made application. I need vba code that I would embed in my application.

I have already downloaded your free version. But it only works for finding addresses by postcode.
 

Владимир

New member
Local time
Today, 19:29
Joined
May 30, 2020
Messages
12
Thanks to Gasman.
I knew that such a method is possible. However, with this method, the browser will open in visible mode (... Visible = True). I think that for my employer and users this will be unacceptable.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:29
Joined
Sep 21, 2011
Messages
14,044
Thanks to Gasman.
I knew that such a method is possible. However, with this method, the browser will open in visible mode (... Visible = True). I think that for my employer and users this will be unacceptable.
Do what other companies do, buy a Post Office licence?. I have only ever used the PostCode DB from a postcode perspective, but I expect it could be used the other way.?


PAF pricing
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:29
Joined
Sep 21, 2011
Messages
14,044
It is unlikely that my employer will want to buy a license.

Nevertheless, thanks to all.
I'm not convinced that the page has to be visible?
I've just commented out that line from some code someone else posted and it still seemed to work.?

Worth a try perhaps?

BTW, Your English is excellent. :)
 

isladogs

MVP / VIP
Local time
Today, 17:29
Joined
Jan 14, 2017
Messages
18,186
Hi
I know where Belarus is...but still can't pronounce your username😀

My evaluation version contains the full feature set. The free version does not.
As it took me several months to develop the code for the full version, do forgive me for being unwilling to provide the code you want for free.
However I will tell you that the code downloads the required data from a reseller called Ideal-Postcodes.
It works perfectly but each search has a small cost which is how they recoup the cost of the Royal Mail annual license.
I spent a long time comparing different ways of getting UK address and postcode data.
AFAIK there is no way of getting the info for free.

If your employer needs a small to medium number of searches, it makes more sense to use a reseller and pay for each search.
For large scale use, it will be more cost effective to buy a Royal Mail license.

I have to say that its an unusual request. Why would your employer have addresses without postcodes?
Anyway, good luck with your quest
 

isladogs

MVP / VIP
Local time
Today, 17:29
Joined
Jan 14, 2017
Messages
18,186
@Gasman
Thanks for the link in post #3. That seems to be a new service as it wasn't available when I was working on this a couple of years ago.
I see that it provides up to 50 free searches a day and seems to work well,
For small scale use, it would be a Good choice

Whilst it wouldn't be easy to do webscraping from that site, the OP could easily add a Web browser control to an Access form which points to the site.
With some effort, he/she could then scrape the result, extract the postcode and paste it into a table.
.
 

Владимир

New member
Local time
Today, 19:29
Joined
May 30, 2020
Messages
12
isladogs, Владимир = Vladimir

Gasman, You are absolutely right!
The result of my work:

Code:
Public Function seachPostcode(ByVal txtAddress As String) As String
    Dim ie As Object
    Dim tempStr As String
    Dim myArray() As String
    Dim i As Integer
    
    Dim myDict As Dictionary
    Dim varItem As Variant
    
    Set ie = CreateObject("Internetexplorer.application")
    
    ' invisible Internet Explorer
    ie.Visible = False
 
    ie.navigate ".../192.com/places/"
 
    While ie.busy
        DoEvents
    Wend
 
    ie.Document.getElementbyID("where_location").Value = txtAddress
 
    ' press button
    ie.Document.Forms(0).submit

    While ie.busy
        DoEvents
    Wend

    tempStr = Trim(ie.Document.getElementbyID("ont-result-items").InnerText)

    ie.Quit
    Set ie = Nothing
    
    myArray = Split(tempStr, "Postcode details")
    
    ' create an object and assign a link to it a variable
    Set myDict = New Dictionary
    
    If UBound(myArray) > 0 Then
        For i = LBound(myArray) To UBound(myArray) - 1

            While myArray(i) Like (vbNewLine & "*")
                myArray(i) = Trim(Right(myArray(i), Len(myArray(i)) - 2))
            Wend
              
            While myArray(i) Like ("*" & vbNewLine)
                myArray(i) = Trim(Left(myArray(i), Len(myArray(i)) - 2))
            Wend
                
            tempStr = Split(myArray(i), vbNewLine)(0)
            
            If UBound(Split(tempStr, ",")) > 0 Then
                tempStr = Split(tempStr, ",")(1)
            End If
            
            tempStr = Trim(tempStr)

            myDict.Item(tempStr) = tempStr
            
        Next
        
        tempStr = ""
        For Each varItem In myDict.Items '
            tempStr = tempStr & varItem & vbNewLine
        Next
        
        seachPostcode = tempStr
    
    End If
        
    Set myDict = Nothing

End Function

Examples of using:
Code:
    MsgBox seachPostcode("A4112, Kimbolton, Leominster, HR6 0HB")
    MsgBox seachPostcode("Brighton 16 Richmond Terrace")
    MsgBox seachPostcode("London, Fulham")
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:29
Joined
Sep 21, 2011
Messages
14,044
@Bxxxxx
We can't even address you :)

Does that mean you have a solution?

FWIW the word is search in English?
 

Владимир

New member
Local time
Today, 19:29
Joined
May 30, 2020
Messages
12
Yes, I used the links that you recommended. I open the browser in invisible mode and get a list of postcodes for my address. If the address is not complete, then there will be more than 1 values.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:29
Joined
Sep 21, 2011
Messages
14,044
If you
Yes, I used the links that you recommended. I open the browser in invisible mode and get a list of postcodes for my address. If the address is not complete, then there will be more than 1 values.
Nice, might help someone else as well (y)
 

isladogs

MVP / VIP
Local time
Today, 17:29
Joined
Jan 14, 2017
Messages
18,186
Hi Vlad
Code looks good but I get an error with the line Dim MyDict as Dictionary

I've tried various workarounds such as
Dim MyDict
...
Set MyDict=CreateObject("Scripting.Dictionary")

but then get error 424 on the GetElementbyID line

Late here and about to sign off so no time to investigate properly
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:29
Joined
May 7, 2009
Messages
19,169
I think this is wrong unless Option Base 1 is in use:

If UBound(myArray) > 0
 

Users who are viewing this thread

Top Bottom