【发布时间】:2018-05-18 22:59:54
【问题描述】:
我正在尝试自动登录:
https://www.check-mot.service.gov.uk/
但是输入文本框的ID是随机变化的,有没有办法扫描代码并确定它的当前ID?
我尝试过使用GetElementsByTagName,但没有奏效。
当我使用检查元素时,它会将我带到这一行:
下面这行代码随机变化的是202413237510。
<input name="202413237510" class="form-control" id="202413237510" type="text" value="">
下面的周边代码:
<form name="moth-search" id="EVL" action="/" method="POST">
<fieldset>
<legend class="form-title heading-medium visuallyhidden">Enter the vehicle registration</legend>
<input name="_csrf_token" type="hidden" value="7A9313B6-6834-04E2-56BE-D6966FFE041F">
<div class="form-group apiary-22453 ddt">
<label class="form-label form-label-bold" for="1700806253">
<span>Do not fill this field</span>
<span class="form-hint">For example, CU57ABC</span>
</label>
<input name="1700806253" tabindex="-1" class="form-control" id="1700806253" type="text" value="">
</div>
<div class="form-group is-on-show tyu-33">
<label class="form-label form-label-bold" for="reg-number">
<span>Do not enter anything in this field</span>
<span class="form-hint">For example, CU57ABC</span>
</label>
<input name="reg-number" tabindex="-1" class="form-control" id="reg-number" type="text" value="">
</div>
<div class="form-group hoth-field it-290">
<label class="form-label form-label-bold" for="202413237510">
<span><span class="sr-only">Enter your</span> Registration number (number plate) <span class="sr-only">into this field only</span></span>
<span class="form-hint">For example, CU57ABC</span>
</label>
<input name="202413237510" class="form-control" id="202413237510" type="text" value="">
</div>
<div class="form-group it-290 salad-box">
<label class="form-label form-label-bold" for="vehicle-manufacturer">
<span>This field should be left empty</span>
<span class="form-hint">For example, CU57ABC</span>
</label>
<input name="vehicle-manufacturer" tabindex="-1" class="form-control" id="vehicle-manufacturer" type="text" value="">
</div>
<div class="form-group keep-hidden isOnshow">
<label class="form-label form-label-bold" for="registration">
<span>Do not fill this field</span>
<span class="form-hint">For example, CU57ABC</span>
</label>
<input name="registration" tabindex="-1" class="form-control" id="registration" type="text" value="">
</div>
<div class="form-group bee-hive tyu-33">
<label class="form-label form-label-bold" for="registration-number">
<span>Do not fill this field</span>
<span class="form-hint">For example, CU57ABC</span>
</label>
<input name="registration-number" tabindex="-1" class="form-control" id="registration-number" type="text" value="">
</div>
【问题讨论】:
-
您可以添加您现在使用的 VBA 来解析文档 html 吗?我可能会向您展示正则表达式
name="(\d)*" class="form-control" id="(\d)*"表达式以及如何提取 id -
要获取当前 ID,您可以尝试
Set post = HTML.querySelector("input.form-control"): MsgBox post.getAttribute("id")这里HTML是HTMLDocument和post是Object。如果我能理解您的要求。
标签: ms-access internet-explorer vba getelementbyid