使用宏将多个网页(1个网站,多个选项卡以选择)提取到Excel中

时间:2015-03-17 21:24:46

标签: excel excel-vba web vba

我是学习和理解宏的新手,我非常渴望学习!

我正在尝试从1个网站但从多个页面以表格的形式提取数据。以下是第一个网页

第一个网页 - http://www.foxsports.com/college-basketball/abilene-christian-wildcats-team-stats?season=2014&category=SCORING&type=1

我希望从这个网页中仅提取表格。完成后,在表格右侧,您可以看到一个包含多个选项(团队)的下拉框。然后我想继续为每个团队获取表格(所以来自Abilene Christian - > Youngstown State)

我希望我已经提供了足够的清晰度,以便能够获得一些帮助和反馈!

非常感谢

1 个答案:

答案 0 :(得分:0)

以下是迄今为止我能够提出的内容!我不知道如何让它循环或能够获得我正在寻找的所有数据..这只是我需要的许多网页中的一个的表...

Sub BasketballStats()

    Dim xmlHttp As Object
    Dim TR_col As Object, TR As Object
    Dim TD_col As Object, TD As Object
    Dim row As Long, col As Long

    Set xmlHttp = CreateObject("MSXML2.XMLHTTP.6.0")
    xmlHttp.Open "GET", "http://www.foxsports.com/college-basketball/louisiana-tech-bulldogs-team-stats?season=2015&category=SCORING&type=1", False
    xmlHttp.setRequestHeader "Content-Type", "text/xml"
    xmlHttp.send

    Dim html As Object
    Set html = CreateObject("htmlfile")
    html.body.innerHTML = xmlHttp.ResponseText

    Dim tbl As Object
    Set tbl = html.getElementById("curr_table")

    row = 1
    col = 1

    Set TR_col = html.getelementsbytagname("TR")
    For Each TR In TR_col
        Set TD_col = TR.getelementsbytagname("TD")
        For Each TD In TD_col
            Cells(row, col) = TD.innerText
            col = col + 1
        Next
        col = 1
        row = row + 1
    Next
End Sub