如何从特定类中获取特定的InnerText?

时间:2017-01-08 22:13:53

标签: vba excel-vba web-scraping excel

<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>
你好!我想从源代码中得到这个: Bet25 Liga 2015/2016

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

一位朋友给了我这个宏,它允许我提取&#34;偶数&#34; 类的 href ,但我需要 InnerText 也是。我必须改变代码?谢谢:))

1 个答案:

答案 0 :(得分:3)

请尝试以下代码:

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