【发布时间】:2020-08-03 22:22:13
【问题描述】:
我发现很难在最终结果页面中提取(不断变化的)XPath 文本。 本站:http://dgftcom.nic.in/licasp/IecDenQuery.asp 很少有 IEC 示例代码是
- 0504057006 ---> 这会产生诸如 FIRM name 之类的结果
- 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 发生了变化,这就是整个代码突然结束的地方。
【问题讨论】:
标签: excel vba selenium selenium-webdriver web-scraping