Sum innertext VBA IE [英] Sum innertext VBA IE
问题描述
我得到了这几个数字,我想要提供的总和,而不是后来总结它
I got this several numbers that I would like to present the sum of rather then having to sum it up afterwards
MsgBox ie.document.getElementsByClassName("post_click_or_post_view_revenue")(0).innertext
MsgBox ie.document.getElementsByClassName("post_click_or_post_view_revenue")(1).innertext
MsgBox ie.document.getElementsByClassName("post_click_or_post_view_revenue")(2).innertext
MsgBox ie.document.getElementsByClassName("post_click_or_post_view_revenue")(3).innertext
我想做类似的事情
MsgBox Sum(ie.document.getElementsByClassName("post_click_or_post_view_revenue").innertext)
这可能吗?
推荐答案
您必须遍历与您的类匹配的一系列标记,将 .innerText
转换为实际数字(看起来像的文本)像一个数字,如果仍然不是一个数字r)当你进步时。
You will have to loop through the series of tags matching your class, converting the .innerText
to an actual number (text that looks like a number if still not a number) as you progress through.
dim dTotal as double, l as long, e as long
with ie.document
l = .getElementsByClassName("post_click_or_post_view_revenue").length - 1
for e = 0 to l
if isnumeric(trim(.getElementsByClassName("post_click_or_post_view_revenue")(e).innertext)) then _
dTotal = dTotal + CDbl(.getElementsByClassName("post_click_or_post_view_revenue")(e).innertext)
next e
end with
msgbox "The total is " & dTotal
现在,这将循环遍历具有匹配类名的所有元素。如果你只想从0到3,那么使用获取e = 0到3
。在进入循环要求所有四个之前,确保实际上有四个。
Now that is going to loop through all of the elements with a matching class name. If you only want to go from 0 to 3 then use for e = 0 to 3
. Just make sure there are actually four of them before you go into a loop asking for all four.
这篇关于Sum innertext VBA IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!