我试图将https://www.soccerstats.com/matches.asp?matchday=3中的值解析到我的Excel中,所以我使用了VBA。但是当我尝试解析来自隐藏元素的数据时,例如

我正在做一个循环,在那里我运行所有的游戏,只有搜索游戏,每队玩超过5次。但是,当我没有输入这个隐藏元素时,我的代码工作得很好。有人能帮助我如何在有隐藏元素或没有隐藏元素的元素中输入我的if help吗?
For i = 1 To .FindElementsByXPath("//*[@class='steam']/../td[@class='sgray'][2]").Count Step 2
If IsNumeric(.FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]").Text) And IsNumeric(.FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]").Text) Then
If CInt(.FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]").Text) > 5 And CInt(.FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]").Text) > 5 Then
league = .FindElementByXPath("((((//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]/../td//preceding::tr[@class='parent'])[last()])/td/font)[1]").Text
If Not IsError(Application.Match(league, Worksheets("Ligas").Range("E:E"), 0)) Then
'Buscar dados se o numero de jogos for numérico
'Encontrar nome da liga
hometeam = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]/../td[1]").Text
awayteam = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i + 1 & "]/../td[1]").Text
homegames = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]").Text
awaygames = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i + 1 & "]").Text
homegoalsscored = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]/following-sibling::td[@class='sgreen'][2]").Text
awaygoalsscored = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i + 1 & "]/following-sibling::td[@class='sgreen'][2]").Text
homegoalsconceded = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgreen'][2])[" & i & "]/following-sibling::td[@class='sred'][1]").Text
awaygoalsconceded = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgreen'][2])[" & i + 1 & "]/following-sibling::td[@class='sred'][1]").Text
gametime = .FindElementByXPath("(//*[@class='steam']/../td[@class='sgray'][2])[" & i & "]/../td[@valign='middle']/font").Text发布于 2021-03-17 22:51:12
如果测试给定节点的.Attribute("style"),返回值可以确定是否显示:none;
例如伪码
If <node>.Attribute("style") = "display:none ;" Then
' do something....
Else
'do something different
End If您还可以使用Instr测试子字符串。
If Instr(<node>.Attribute("style"), "display:none") > 0 Then
' do something....
Else
'do something different
End If<node>是当前迭代中的节点/元素的占位符,无论测试需要什么级别;从您的问题中看不清楚。
https://stackoverflow.com/questions/66680756
复制相似问题