You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VBA Selenium无法通过XPath提取网页球员名称文本问题求助

问题描述

使用VBA结合Selenium从Eurocup赛事网页提取数据时,大部分统计数据均可正常获取,但球员名称始终返回空白。尝试过调整名称格式(全名、简称等)无效,因网站class名称会不定期变更,故采用XPath定位元素。

相关代码
Set ch = New Selenium.ChromeDriver
ch.AddArgument "--headless"
ch.Get "https://www.euroleaguebasketball.net/eurocup/game-center/2023-24/cedevita-olimpija-ljubljana-joventut-badalona/U2023/12/#boxscore"

Set sht = Sheets("Sheet1")
Rw = 1
Base = "//*[@id='main']/div/div/div[2]/div/div[3]/div/div[2]/div/div[1]/div/div[1]/"
For Rw = 1 To 20
    Exists = ch.FindElementsByXPath(Base & "div[1]/div[" & Rw & "]/span").Count
    
    If Exists > 0 Then
    sht.Cells(Rw, 1) = ch.FindElementByXPath(Base & "div[1]/div[" & Rw & "]/span").Text
    sht.Cells(Rw, 2) = ch.FindElementByXPath(Base & "div[1]/div[" & Rw & "]/a/div[1]").Text
    sht.Cells(Rw, 3) = ch.FindElementByXPath(Base & "div[2]/div[1]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 4) = ch.FindElementByXPath(Base & "div[2]/div[1]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 5) = ch.FindElementByXPath(Base & "div[2]/div[2]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 6) = ch.FindElementByXPath(Base & "div[2]/div[2]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 7) = ch.FindElementByXPath(Base & "div[2]/div[3]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 8) = ch.FindElementByXPath(Base & "div[2]/div[3]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 9) = ch.FindElementByXPath(Base & "div[2]/div[4]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 10) = ch.FindElementByXPath(Base & "div[2]/div[4]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 11) = ch.FindElementByXPath(Base & "div[2]/div[5]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 12) = ch.FindElementByXPath(Base & "div[2]/div[5]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 13) = ch.FindElementByXPath(Base & "div[2]/div[5]/div[" & Rw & "]/div/div[3]").Text
    sht.Cells(Rw, 14) = ch.FindElementByXPath(Base & "div[2]/div[6]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 15) = ch.FindElementByXPath(Base & "div[2]/div[6]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 16) = ch.FindElementByXPath(Base & "div[2]/div[6]/div[" & Rw & "]/div/div[3]").Text
    sht.Cells(Rw, 17) = ch.FindElementByXPath(Base & "div[2]/div[7]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 18) = ch.FindElementByXPath(Base & "div[2]/div[7]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 19) = ch.FindElementByXPath(Base & "div[2]/div[8]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 20) = ch.FindElementByXPath(Base & "div[2]/div[8]/div[" & Rw & "]/div/div[2]").Text
    sht.Cells(Rw, 21) = ch.FindElementByXPath(Base & "div[2]/div[9]/div[" & Rw & "]/div/div[1]").Text
    sht.Cells(Rw, 22) = ch.FindElementByXPath(Base & "div[2]/div[9]/div[" & Rw & "]/div/div[2]").Text

    End If
Next Rw
当前状态

Excel中各项统计数字已正常提取(格式可后续调整),但球员名称列显示空白,寻求解决思路。


内容的提问来源于stack exchange,提问作者Danjo9

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 19:14:50