【问题标题】:Insert Label value using VBA使用 VBA 插入标签值
【发布时间】:2018-12-13 05:11:07
【问题描述】:

HTML 代码:

<div class="col-md-6 ng-scope" data-ng-repeat="x in myData ">
    <div class="list-group ng-binding">
        <label for="Which is the cinema hall closest to your residence?"></label>Which is the cinema hall closest to your residence?
        <input name="email2" class="form-control ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required" required="required" type="text" autocomplete="off" data-ng-required="isRequired" data-ng-model="quesAnsModel.answer[x.id]">
    </div>
</div>

如何使用 VBA excel 插入标签为“哪个电影院离您的住所最近?”的文本框的值?

ie.document.getElementsByClassName("col-md-6 ng-scope").value

【问题讨论】:

  • 不清楚你在问什么
  • 建议如何填写带有labal名称的文本框“离你家最近的电影院是哪家?”?
  • 下面的答案对你有用吗?
  • 如果答案对您有用,请记住接受并反馈给回答您其他问题的人。 stackoverflow.com/help/someone-answers

标签: javascript html vba web-scraping


【解决方案1】:

使用 css 属性 = 值选择器既美观又易读

ie.document.querySelector("[for='Which is the cinema hall closest to your residence?']")

标签通常就是这样。如果您实际上需要相邻的输入框(尽管它说电子邮件?),您将使用相邻的兄弟组合器来定位以下输入框

ie.document.querySelector("[for='Which is the cinema hall closest to your residence?'] + input").value = ""

【讨论】:

  • querySelector 返回单个输入让我感到震惊。哇+1。
  • @TinMan 是的。第一个匹配项或 null。 querySelectorAll 将返回一个 nodeList 或 null。
  • Aww..我想我一直用querySelectorAll
  • @TinMan 我不知道在 Selector 和 SelectorAll 之间是否有任何真正的效率差异。我想可能有。我考虑的主要部分是选择器的效率和更少的输入!
  • 我认为querySelector 会在第一次匹配时停止遍历文档节点,因此比querySelectorAll()[0] 更有效。仅供参考:我刚刚完成了对 Craps Calculator 工作的重写。用querySelector() 替换getElementsByClassName()[0] 的所有实例并使用querySelectorAll() 一次将事件添加到多个控件类是坚果!!!
猜你喜欢
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
  • 1970-01-01
  • 2022-07-17
  • 2018-08-25
相关资源
最近更新 更多