Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
885 views
in Technique[技术] by (71.8m points)

vba - How to get a particular InnerText from a specific class?

<tbody>
            <tr>
                <td>
                    <a href="/denmark/1st-division/">1st Division 2016/2017</a>
                </td>
                    <td>
                    </td>
            </tr>
            <tr class="even">
                <td>
                    <a href="/denmark/1st-division-2015-2016/">Bet25 Liga 2015/2016</a>
                </td>
                    <td>

Hi guys! I would like to get this: Bet25 Liga 2015/2016 from that source code.

Sub ExtractHrefClass()

    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", Range("D8").Value, False
        .Send
        Range("E8").Value = Split(Split(Split(.ResponseText, "<tr class=""even"">", 2)(1), "<a href=""", 2)(1), """", 2)(0)
    End With

End Sub

A friend gave me this macro that allows me to extract the href of that "even" class, but i need to have the InnerText too. where i have to change the code? Thanks :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try the below code:

Sub ExtractHrefClass()

    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", Range("D8").Value, False
        .Send
        a = Split(Split(Split(.ResponseText, "<tr class=""even"">", 2)(1), "<a href=""", 2)(1), """>", 2)
    End With
    Range("E8").Value = a(0)
    Range("F8").Value = Split(a(1), "<", 2)(0)

End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...