我正在使用vba代码从特定网页中提取数据。我需要在网页中粘贴唯一的数字,然后提取有关这些数字的详细信息,并将其粘贴到该数字旁边的Excel中。
问题是,当该号码无效时,我从网页上收到一条消息,点击确定,以便我可以在网页中粘贴下一个唯一号码。 代码可以找到,直到粘贴了一些无效的数字并且网页消息来了。
下面是我的VBA代码:
Set iedoc = ie.document
For i = 2 To k
With iedoc.forms(0)
Worksheets("ID").Select
'----------------
iedoc.all.txtNum.Value = Cells(i, "b").Value
ie.document.getElementById("cmdSearch").Click
Do While ie.Busy: DoEvents: Loop
Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Application.Wait Now + TimeSerial(0, 0, 1)
Cells(i, "c").Value = iedoc.all.LastName.Value
Cells(i, "d").Value = iedoc.all.txtAddress1.Value
Cells(i, "e").Value = iedoc.all.hdnName.Value
ie.document.getElementById("cmdCancel").Click
Do While ie.Busy: DoEvents: Loop
Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'Application.Wait Now + TimeSerial(0, 0, 1)
End With
Next i
MsgBox "Downloading information is completed", vbOKOnly"
以下是我发现对网页中的消息有用的HTML代码
Function OnLoadRoutine()
{
widthScreen = document.body.clientWidth ;
heightScreen = document.body.clientHeight ;
oFrm=document.frm;
preLoad();
alert("Record not found for number: 275016159F7");
With (oFrm)
{
if (optAll.checked == false && optSrchType[1].checked == false &&
optSrchType[2].checked == false && optSrchType[3].checked == false &&
optSrchType[4].checked == false)
{
optSrchType[0].status = true;
optSrchType[0].checked = true;
txtDCNNum.focus();
}
} }