【问题标题】:VBA Excel Dynamic HTML code - scraping seleniumVBA Excel 动态 HTML 代码 - 抓取硒
【发布时间】:2021-10-10 12:37:28
【问题描述】:

我正在尝试自动填写在线表单,但输入字段似乎在每次更新时生成,具有不同的 ID,由于 ID 总是在变化,因此不允许填写。

有什么解决办法吗?建议?

Code1 - 在这种情况下,我可以通过 name="taxNumber" <input id="vfenif-1373-inputEl" type="text" size="1" name="taxNumber" class="x-form-field x-form-required-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" autocomplete="off" aria-invalid="false" data-errorqtip="" style="width: 100%;">

Private gc As New Selenium.ChromeDriver ... gc.FindElementByName("taxNumber").SendKeys ("123456789") ...

Code2 在这种情况下它可以工作一次,但如果你刷新 ID,它会发生变化,然后就不能工作了 <td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1047 x-grid-cell-last x-unselectable " id="ext-gen1581"><div unselectable="on" class="x-grid-cell-inner " style="text-align:left;">Submeter Pedido</div></td>

...刷新后

<td role="gridcell" class="x-grid-cell x-grid-td x-grid-cell-gridcolumn-1047 x-grid-cell-last x-unselectable " id="ext-gen1580"><div unselectable="on" class="x-grid-cell-inner " style="text-align:left;">Submeter Pedido</div></td>

【问题讨论】:

  • 网站是公开的吗?如果表始终有固定数量的td,那么您可以将表作为目标,然后是 nth-children 的 td?
  • 是的,我记得,但是链接可以换行。这不是理想的解决方案,但它有效。在 IE 中它确实是这样的。 ... Dim HTMLDoc As MSHTML.HTMLDocument Dim HTMLInput As MSHTML.IHTMLElement, HTMLInput2 As MSHTML.IHTMLElement, HTMLInput3 As MSHTML.IHTMLElement Set HTMLInput = HTMLDoc.getElementById("gridview-1048-body") Set HTMLInput2 = HTMLInput.getElementsByTagName("tr")(6) Set HTMLInput3 = HTMLInput.getElementsByTagName("td")(2) HTMLInput3.click 在 Selenium 上我该怎么做?
  • 我不使用 Selenium,但快速谷歌有很多答案 - Example。检查对象浏览器? @阿桑托斯

标签: excel vba selenium screen-scraping


【解决方案1】:

假设有一个类名为“unselectable”的 td,看看这个 xpath 是否有效

gc.FindElementByXPath("//td[contains(@class,'x-unselectable') and contains(@id,'ext-gen')]")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 2014-11-25
    相关资源
    最近更新 更多