【发布时间】:2016-06-26 06:00:23
【问题描述】:
我需要使用 VBA 自动填写网络表单。当我手动填写邮政编码字段(htmIntCEP)时,它会触发一些填充的Javascript代码,以及其他一些字段(htmStrCidade、htmStrEndereco等)。 当我尝试在 VBA 中制作 tha 时,就会出现问题。我可以填写邮政编码字段,但看不到 Javascript 调用的位置。我会尝试“onblur”事件,但没有这样的事件。
网页中的表格和Javascript(包括文件)如下。 (原网址为:http://seletivo2016.com.br/ler.asp?dir=inscricao&pg=etapa1agendada&enem=1)
有人知道吗?提前致谢。
卡洛斯
...
<tr>
<td>
<input name="htmIntCEP" type="text" class="formulario" id="htmIntCEP" size="8" maxlength="8" onkeypress="return m_edit(event, this, '########');" />
<span><a href="http://m.correios.com.br/movel/buscaCepConfirma.do" target="_blank" tabindex="-1"
onclick="event.preventDefault(); window.open(this.href, this.target, 'width=320, height=350, left=' + event.x + ', top=' + event.y);">buscar cep</a></span>
</td>
<td>
<input name="htmStrEndereco" type="text" class="formulario" id="htmStrEndereco" onblur="TrimCampo(this)" size="40" maxlength="50" />
</td>
<td>
<input name="htmStrNumero" type="text" class="formulario" id="htmStrNumero" onblur="TrimCampo(this)" size="10" maxlength="10" />
</td>
</tr>
<tr>
<td>Complemento:</td>
<td colspan="2">Bairro:</td>
</tr>
<tr>
<td>
<input name="htmStrComplemento" type="text" class="formulario" id="htmStrComplemento" size="20" maxlength="20" onblur="TrimCampo(this)" /></td>
<td colspan="2">
<input name="htmStrBairro" type="text" class="formulario" id="htmStrBairro" size="30" maxlength="30" onblur="TrimCampo(this)" /></td>
</tr>
<tr>
<td>
<abbr title="Estado">UF</abbr>:</td>
<td colspan="2">Cidade:</td>
</tr>
<tr>
<td>
<input name="htmStrUF" class="formulario" id="htmStrUF" placeholder="Informe o CEP."
readonly="readonly"/>
</td>
<td colspan="2" id="celCidade">
<input name="htmStrCidade" class="formulario" id="htmStrCidade" placeholder="Informe o CEP."
readonly="readonly"/>
<script type="text/javascript" src="/scripts/cep.js"></script>
<script type="text/javascript">
$(function () {
$('#celCidade').parent().parent().parent().parent().cepform('htmIntCEP',
'htmStrUF', 'htmStrCidade', 'htmStrEndereco', 'htmStrNumero', 'htmStrBairro', 'htmStrComplemento');
});
</script>
</td>
</tr>
包含JAVASCRIPT代码的开头
(function ($) {
var server = location.hostname === "localhost" ?
"localhost:30603" : location.hostname.match(/(fmu\.dev)$/ig) ? "api.fmu.dev/CEP" : "api.fmu.br/CEP";
var cache = {};
// ReSharper disable once InconsistentNaming
function CEP(form, cep, uf, cidade, endereco, numero, bairro, complemento) {
var api, apic, sending, loader, loading, w, h, self = this;
一段VBA代码:
我想我也应该发布一段 VBA 代码:
Sub test()
Dim IEApp As InternetExplorer
Dim HTMLDoc As HTMLDocument
Dim URL As String
Dim Formulario As HTMLFormElement
URL = "http://seletivo2016.com.br/ler.asp?dir=inscricao&pg=etapa1agendada&enem=1"
Set IEApp = New InternetExplorer
IEApp.Visible = True
IEApp.Navigate URL
Do
DoEvents
Loop Until IEApp.ReadyState = 4
Set HTMLDoc = IEApp.Document
Set CampoTexto = Formulario.elements("htmIntCEP")
CampoTexto.Value = "01313010"
' Here I thought to put an eventfire
【问题讨论】:
标签: javascript vba web-scraping