【问题标题】:Excel VBA Scraping - MorningstarExcel VBA 抓取 - 晨星
【发布时间】:2015-03-30 13:40:16
【问题描述】:

我想用一个 excel vba 代码在这个链接上显示财务信息,但是我目前的代码无法做到这一点。

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

我该怎么做?

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

Sheets("Morningstar").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

【问题讨论】:

标签: vba excel scrape


【解决方案1】:

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

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

这里有一些使用 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

祝你好运。记得定期审查,因为网站更改可能会破坏抓取代码。

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 2016-09-08
    • 2016-06-10
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多