Excel VBA刮痧 - 晨星

时间:2015-03-30 13:40:16

标签: vba excel-vba scrape excel

我想使用excel vba代码来查看此链接上的财务状况,但无法使用我当前的代码执行此操作。

我只想复制并粘贴所有数据。它是否包含其他信息并不重要。

我该怎么做?

链接:http://financials.morningstar.com/cash-flow/cf.html?t=SPN&region=usa&culture=en-US Sub MS()

表("晨星&#34)clearContents中。     my_Page =" http://financials.morningstar.com/cash-flow/cf.html?t=SPN&region=usa&culture=en-US"

Sub MS()

Sheets("Morningstar").ClearContents
    my_Page = "http://financials.morningstar.com/cash-flow/cf.html t=SPN&region=usa&culture=en-US"
    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Visible = True
        .Navigate my_Page
        Do Until .ReadyState = 4: DoEvents: Loop
    End With

   Application.EnableEvents = False
   IE.ExecWB 17, 0
   Do Until IE.ReadyState = 4: DoEvents: Loop
   IE.ExecWB 12, 2
   ActiveSheet.PasteSpecial Format:="HTML", link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
   Range("A1").Select

   IE.Quit
    Application.EnableEvents = True
End Sub

1 个答案:

答案 0 :(得分:1)

一种方法是使用MSHTML库(您需要在引用中启用它)。

将html文档加载到对象中。 IE.document 遍历元素以提取所需的数据。

以下是使用VBA解析信息的一些很好的示例。您可以使用这些技术来获取数据: Parse HTML content in VBA Pulling a table out of a mess of HTML w/ VBA & Excel http://www.ozgrid.com/forum/showthread.php?t=184695

祝你好运。请记住定期查看,因为网站更改可能会破坏代码。

相关问题