I’m trying to find a way to get the correct and full URL of a link.
Sometimes, with item.href
, I get the full url and sometimes only shows about:something
or about:..something
or about:../something
In this case with my current code, I iterate all links in this URL and want to get the full URL of the link related with text “VLOOKUP”. The answer I get with my current code is
about:excel_vlookup.php
and if I want to simply concatenate the base_url (https://www.w3schools.com/excel/index.php) with Replace("about:excel_vlookup.php","about:","")
, I would get a wrong answer
like this https://www.w3schools.com/excel/index.phpexcel_vlookup.php
instead of https://www.w3schools.com/excel/excel_vlookup.php
that is the correct full URL when I put mouse over that link.
May someone know how to do this?
Sub full_url()
Dim htmlDoc As New HTMLDocument
Dim links As Object
Dim i As Integer
With New ServerXMLHTTP60
.Open "Get", "https://www.w3schools.com/excel/index.php", False
.send
htmlDoc.body.innerHTML = .responseText
End With
Set links = htmlDoc.body.getElementsByTagName("a")
With links
For i = 0 To .Length - 1
If .Item(i).innerText Like "*VLOOKUP*" Then
Debug.Print .Item(i).href
End If
Next
End With
End Sub