gpt4 book ai didi

excel - 从网站获取背景颜色

转载 作者:行者123 更新时间:2023-12-04 21:32:15 24 4
gpt4 key购买 nike

嗨,我正在尝试从网站获取背景颜色,以便将其与其他操作进行比较。就像网站购买按钮的背景颜色一样。

Sub Colorfinder()
Dim oIE As New InternetExplorer
Dim oHtml As HTMLDocument
Dim tags As Object
Dim HTMLtags As IHTMLElementCollection
Dim HTMLtag As IHTMLElement

With oIE
.Visible = True
.navigate "https://www.gdax.com/trade/LTC-EUR"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set oHtml = .document
End With


'this is needed to wait until the page is totally loaded
Do: Set tags = oHtml.getElementsByClassName("OrderBookPanel_text_3fH-g")(0): DoEvents: Loop While tags Is Nothing


'getting the element that it is about
Do: Set HTMLtags = oHtml.getElementsByClassName("OrderForm_toggle_31S34"): DoEvents: Loop While HTMLtags.Length = 0

Set HTMLtag = HTMLtags(0).Children(0)
Debug.Print HTMLtag.innerText

'this is the problem
Debug.Print HTMLtag.Style.backgroundColor

End Sub

我从其他人的溢出用户那里得到了这个想法。但它没有用。 link stuckoverflow

最佳答案

试试下面的代码:

Sub Colorfinder()

With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "https://www.gdax.com/trade/LTC-EUR"
Do While .Busy Or .readyState < 4: DoEvents: Loop
With .Document
Do While .getElementsByClassName("OrderBookPanel_text_3fH-g").Length = 0: DoEvents: Loop
Do While .getElementsByClassName("OrderForm_toggle_31S34").Length = 0: DoEvents: Loop
With .parentWindow
.execScript "var e = document.getElementsByClassName('OrderForm_toggle_31S34')[0].children[0];"
.execScript "e.style.backgroundColor = window.getComputedStyle(e,null).getPropertyValue('background-color');"
End With
Debug.Print .getElementsByClassName("OrderForm_toggle_31S34")(0).Children(0).Style.backgroundColor ' rgb(77, 165, 60)
End With
End With

End Sub
.execScript在 HTML 文档中执行 JScript 代码,这就是为什么语法使用 var , ' , [];等,变量 e是文档范围内声明的目标节点,它是实际计算的背景值,只是放入 .backgroundColor属性(property)。使用 .execScript是我发现到达 window.getComputedStyle 的唯一方法方法,它实际上完成了工作。

关于excel - 从网站获取背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49220455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com