Reputation: 3
I am trying to get some information from a webpage using an excel macro, VBA.
I have the InternetExplorer.document object, but don't find a way to locate the exact info that I need.
The HTML part of what I am looking for looks like this:
<a title="BE xxx.xxx.xxx - straat 70 - 3630 - Maasmechelen" class="leftalign floatleft" href="Page_companydetail.asp?vat=xxxxxxxxx" target="_blank">
Oprichter van een onderneming natuurlijk persoon BE xxx.xxx.xxx
The information I want is the title here. I tried a lot of things, but can't manage to single this element out and get the title.
So 1. Is there a way to get elements by title (Title starts with BE), or by class sinds this information is the only one on the page that has class "leftalign floatleft"
Upvotes: 0
Views: 15339
Reputation: 8941
Yes ... knowing that the title is just another attribute of the <a>
tag, you can cycle through all elements of concern using e.g.
HtmlDocument.GetElementsByTagName(String)
method
and use the
HtmlElement.GetAttribute(String)
method
to see if a title attribute exists and what's the value of it
see Reading Web Pages using Excel VBA for some more information
Upvotes: 1
Reputation: 5677
Something like this should work, I'm assuming you already have a pointer to the IE or Document Object.
Public Sub getTitleElement()
Dim myElement As Object
'Assuming you already have IE object/Document
Set myElement = IE.Document.getElementsByClassName("leftalign floatleft")(0)
Debug.Print myElement.Title
End Sub
Upvotes: 0