PDA

View Full Version : Why cant i get the contents of the title tag ?



neeeel
06-13-2011, 10:44 AM
sub loadURLHead(URL As String) As String
Dim xml As Object
dim html as object
Dim result As String
Dim tbl As Object, obj As Object, obj2 As Object
Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
With xml
.Open "HEAD", URL, False
.send
End With
result = xml.responseText
Set html = CreateObject("htmlfile")
html.body.innerHTML = result
Set obj = html.getElementsByTagName("HEAD")
Debug.Print (obj.Length)
Set obj = html.getElementsByTagName("title")
Debug.Print (obj.Length)
MsgBox (obj(0).innerText)
End sub

When I call this sub with a URL, it works ok, it outputs length 1 for both the head and title elements, meaning that there is 1 element of each, but when I try and get any data from the elements, there is nothing, "", a blank. I dont understand what I am doing wrong, as I can get data from the body of an html document ok. I am sure it is something simple due to my lack of understanding of some of the objects I am using, but there doesnt seem to be much documentation out there, ive spent the last couple of days looking and learning.

thanks for any help