0

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"

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this works perfect for the other elements on the page, but not for what I need. I tried something very similar. I discovered something new. I see the information I need if I use the DOM-explorer, but if I display the source of the page, I cant find it? Is there some protection on it / can this be my problem?
A possibly limiting factor could be that GetAttribute "exposes only those attributes that are common to all elements, leaving out those that only apply to certain types of elements" ... acc. to msdn.microsoft.com/en-us/library/… ... I don't know if this is relevant to VBA/Excel and I have no experience with it as I am searching mostly for standard attributes
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.