【问题标题】:Scrape a bloomberg website to get market cap into excel [duplicate]刮掉一个Bloomberg网站以将市值变成Excel [重复]
【发布时间】:2019-11-22 21:22:58
【问题描述】:

我正在尝试从“https://www.bloomberg.com/quote/206:HK”网站提取市值 在这种情况下为 1.059B。

我想将市值值提取到一个 Excel 列中,以获取彭博股票代码列表。我想在 VBA 中执行此操作,不幸的是不知道从哪里开始。

基本上,我有一个专栏,其中包含所有指向bloomberg 的链接。我想在它旁边的列中提取市值值

【问题讨论】:

    标签: excel vba web-scraping


    【解决方案1】:

    您可以使用下面的代码做到这一点。我使用两个步骤来获得价值。可以猜测它也适用于 css 类 value__b93f12ea。但是类名包含一个十六进制值,我知道动态生成此类标识符时经常出现这种情况。

    Sub ScrapMarketCap()
    
    Dim browser As Object
    Dim url As String
    Dim nodeMarketCapAll As Object
    Dim nodeMarketCap As Object
    
      url = "https://www.bloomberg.com/quote/206:HK"
    
      'Initialize Internet Explorer, set visibility,
      'Call URL and wait until page is fully loaded
      Set browser = CreateObject("internetexplorer.application")
      browser.Visible = True
      browser.navigate url
      Do Until browser.ReadyState = 4: DoEvents: Loop
    
      'Get all html elements withh the css class "dataBox marketcap numeric"
      'in a node collection and get the first one by index (0)
      'There will be only one element with this class. But we still need to
      'specify the index, because we need the specific element from the node list
      '
      'We want this html in our dom object
      '<section class="dataBox marketcap numeric">
      '  <header class="title__49417cb9"><span>Market Cap</span></header>
      '  <div class="value__b93f12ea">1.074B</div>
      '</section>
      Set nodeMarketCapAll = browser.document.getElementsByClassName("dataBox marketcap numeric")(0)
    
      If Not nodeMarketCapAll Is Nothing Then
        'If we got the element
        'We take the value of the market cap from the first div tag
        Set nodeMarketCap = nodeMarketCapAll.getElementsByTagName("div")(0)
    
        If Not nodeMarketCap Is Nothing Then
          'If we got the div
          'We take the value from it
          MsgBox Trim(nodeMarketCap.innertext)
        End If
      End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2012-03-05
      • 2019-03-01
      • 1970-01-01
      • 2017-10-09
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-28
      相关资源
      最近更新 更多