0

Disclosure: I'm an office clerk trying to automate the most boring copy-paste part of my job and have 0 knowledge of VBA or HTML. Thank you for your patience with me.

I was able to successfully parse data from intranet page, that I require, by using GetElementByID, however, this particular piece of information doesn't have ID.

I tried getting it using GetElementsByClassName, but it produced error above and I can't figure out why. It seems to work for other people, not for me.

This is my code.

Sub ExtractFromEndeca()
 Dim ie As InternetExplorer
 Dim html As IHTMLDocument
 Dim DescData As MSHTML.IHTMLElementCollection
 Set ie = CreateObject("InternetExplorer.Application")
 ie.Visible = False
 ie.Navigate Range("h3")
 While ie.Busy
     DoEvents
     Wend
     While ie.ReadyState < 4
     DoEvents
     Wend
     Set doc = CreateObject("htmlfile")
     Set doc = ie.document
     Set DescData = doc.getElementsByClassName("propertyList")
     Set Data = doc.getElementById("findSimilarOptions2")
     Sheet3.Cells(1, 1) = Data.innerText
     Sheet3.Cells(100, 1) = DescData.innerText
     ie.Quit
     Set ie = Nothing

End Sub

This is a fragment of HTML from intranet page, that I require.

<table class="propertyList" cellpadding="0" cellspacing="0" width="100%">
<thead>
    <th width="60px">&nbsp;</th>
    <th align="left" colspan=1 width="130px" nowrap>Item Information</th>
    <th>&nbsp;</th>

</thead>


    <tr>
    <td rowspan=6 valign=top width="60px"><a href="Wierd looking link"><img border=0 alt="Locate Item" src="Wierd Gif"></a>
    </td>
    <td valign=top nowrap><b>Property(1)</b></td>
    <td>Value(1)</td>


    </tr>
    <tr>
        <td nowrap><b>Property(2)</b></td>
        <td>Value(2)</td>
    </tr>
    <tr>
        <td nowrap><b>Property(3)</b></td>
        <td>Value(3)</td>
    </tr>
    <tr>
        <td nowrap><b>Property(4)</b></td>
        <td>Property(4)</td>
        </tr>
    <tr>
        <td nowrap><b>Property(5)</b></td>
        <td>Value(5)</td>
    </tr>
    <tr>
        <td nowrap><b>Property(6)</b></td>
        <td>Value(6)</td>
    </tr>
    </table>
5
  • 1
    Possible duplicate of VBScript GetElementsByClassName not supported? Commented Jan 13, 2020 at 8:30
  • 1
    I see no elements with an ID of findSimilarOptions2 in your example. Commented Jan 13, 2020 at 8:48
  • @braX That's the one I was able to get actually. So I thought it is not relevant to show it in HTML sample. Now I'm trying to get table with class "propertylist". However, I thought there is a conflict between those lines, maybe? So I'm showing it in VBA code. Commented Jan 13, 2020 at 9:09
  • 1
    getElementsByClassName() creates a node collection. The elements of the node collection have indexes. The first index is 0. If you want the first element you must write Set DescData = doc.getElementsByClassName("propertyList")(0) The method getElementByID() doesn't create a node list. So it give no indexes. Commented Jan 13, 2020 at 13:50
  • @Zwenn Thanks, that may be the reason, but I'm pretty sure I tried that, however, after rebooting my laptop, it has magically started to work =). Thanks again you for your time and your help. Commented Jan 14, 2020 at 6:18

0

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.