gpt4 book ai didi

excel - 在 Selenium VBA 中提取变化的 XPath

转载 作者:行者123 更新时间:2023-12-04 22:22:29 26 4
gpt4 key购买 nike

我发现很难在最终结果页面中提取(更改)XPath 文本。
本站: http://dgftcom.nic.in/licasp/IecDenQuery.asp
很少有 IEC 示例代码是

  • 0504057006 ---> 这会产生结果,例如 公司 姓名
  • 0504057007 ---> 这会产生无效的 IEC 代码消息
  • 0504057006
  • 0504057007
  • 0504057006
    Option Explicit

    Public Sub EntityList()

    Dim bot As WebDriver
    Dim count As Long

    Set bot = New WebDriver
    bot.Start "Chrome"
    count = 1
    While (Len(Range("A" & count)) > 0)

    bot.Get "http://dgftcom.nic.in/licasp/IecDenQuery.asp"
    bot.FindElementByXPath("//input[@type='text'][@name='IEC']").SendKeys Range("A" & count)
    bot.FindElementByXPath("//input[@type='submit'][@name='B1']").Click

    Range("B" & count) = bot.FindElementByXPath("/html/body/table[2]/tbody/tr/td/font/strong").Text
    'Range("B" & count) = bot.FindElementByXPath("//table/tbody/tr[1]/td[1]").Text

    bot.Wait 1000

    count = count + 1
    Wend
    bot.Quit
    End Sub

  • 这里的问题是,当输入下一个 IEC 代码时,XPath 发生了变化,这就是整个代码突然结束的地方。

    最佳答案

    试试下面的 XPath。

    //font[contains(.,'IEC :')]

    代码 :
    Range("B" & count) = bot.FindElementByXPath("//font[contains(.,'IEC :')]").Text

    关于excel - 在 Selenium VBA 中提取变化的 XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61339005/

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