Return Website Inspect data

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,633
Office Version
  1. 365
Platform
  1. Windows
I am trying to scrape Find and update company information - GOV.UK to get the addresses of a number of businesses in the UK using the business company registration number.

Using VBA I can navigate to a businesses page
e.g.
The page for Barclays Bank is BARCLAYS BANK PLC overview - Find and update company information - GOV.UK

Within this page the businesses registered address is shown
1731683909278.png


With the inspection elements of
1731683944325.png


I have managed to find other elements I need but I can't seem to work out how to get the text that is the registered address.


TIA
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You haven't said which library you're using (MSHTML or Selenium). This is Selenium:

VBA Code:
    Dim dt As WebElement
    Dim dl As WebElement
    
    Set dt = driver.FindElementByXPath("//dt[text()='Registered office address']")
    Set dl = dt.FindElementByXPath("./..")
    Debug.Print Split(dl.Text, vbLf)(1)
 
Upvote 0
You haven't said which library you're using (MSHTML or Selenium). This is Selenium:

VBA Code:
    Dim dt As WebElement
    Dim dl As WebElement
   
    Set dt = driver.FindElementByXPath("//dt[text()='Registered office address']")
    Set dl = dt.FindElementByXPath("./..")
    Debug.Print Split(dl.Text, vbLf)(1)
I don't recognise the code you have provided so I am assuming I am using MSHTML.
 
Upvote 0
For MSHTML, try one of these:

VBA Code:
    Dim HTMLdoc As HTMLDocument
 
    Dim dl As HTMLDListElement
    Set dl = HTMLdoc.getElementsByTagName("dl")(0)
    Debug.Print dl.Children(1).innerText
 
    Dim dd As HTMLDDElement
    Set dd = HTMLdoc.getElementsByTagName("dd")(0)
    Debug.Print dd.innerText

I should clarify that the previous code was for Seleniumbasic. There's also SeleniumVBA which is actively maintained and updated. It also has the very useful feature of automatically downloading the driver library version to keep it synchronised with the current web browser version. For Seleniumbasic you have to download and install the latest web driver version (Microsoft Edge Web Driver or Chrome ChromeDriver) yourself to keep it compatible with the current web browser, which is typically downloaded and updated automatically.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,927
Messages
6,175,432
Members
452,641
Latest member
Arcaila

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top