【问题标题】:I want to extract the element webpage title on vba excel我想在vba excel上提取元素网页标题
【发布时间】:2017-03-05 22:21:18
【问题描述】:

我正在尝试使用 VBA 从该网站中提取此代码中格式文本中的元素标题

<div class="train-logo
      train-logo-monochrome
      train-logo--trenitalia-monochrome
      train-logo--frecciarossa-monochrome" title="Trenitalia">
    </div>

VBA:

For Each treno In IE.Document.getelementsbytagname("div")
    If treno.getattribute("title") Then
        Cells(rownumber2, "u").Value = treno.innertext

【问题讨论】:

  • 你是如何尝试这样做的,当你运行你的代码时会发生什么?
  • 我在 excel 上开发了一个宏,它可以访问 Internet exploerer 并获取元素作为例如价格。在这种情况下,我想从这个 url trainline.eu/search/milano/firenze/2017-03-21-14:00 获取格式文本 title="trenitalia"
  • 如果您有代码,最好将其包含在您的问题中,否则很可能会被关闭。
  • 我在 IE.Document.getelementsbytagname("div") If treno.getattribute("title") Then Cells(rownumber2, "u").Value = treno 中尝试了这个 vba 代码.innertext

标签: vba excel parsing web-scraping


【解决方案1】:

这样的事情应该可以工作:

Dim treno, t

For Each treno In IE.Document.getelementsbytagname("div") 
    t = treno.getattribute("title")
    If t <> "" Then Cells(rownumber2, "u").Value = t
Next treno

从您的问题中不清楚您需要从页面中读取多少个:如果只有一个,您可以在获得价值后Exit For

【讨论】:

  • 宏运行但不将值标题粘贴到单元格上再次阅读网页
猜你喜欢
  • 2021-12-23
  • 1970-01-01
  • 2014-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-18
  • 2020-12-05
  • 1970-01-01
相关资源
最近更新 更多