2017-08-27 60 views
2

我试图输入包裹ID:220022400803300并试图获得结果,但即使在将包裹ID放入搜索框并单击提交按钮后,它仍未返回结果。如何提交表单数据excel vba

任何人都可以请帮助我,或者如果有更好的方法来做到这一点,请让我知道。

该网站是http://eringcapture.jccal.org/caportal/CAPortal_MainPage.aspx访问该网站后我点击Search your Real Property. Click Here.在页面的底部,那么我选择parcel #单选按钮,然后把那个大包的ID号220022400803300,点击Search按钮,但它不返回结果发现,同时手动将其做给出1个结果。

Option Explicit 
Option Compare Text 

Dim fRD As Long, i As Long, fSR As Long, j As Long 
Dim pID As String 
Dim IE As SHDocVw.InternetExplorer 
Dim Doc As MSHTML.HTMLDocument 
Dim urL As String 
Dim fnd As Boolean 

Sub genOP() 

With RD 

    fRD = .Range("A" & .Rows.Count).End(xlUp).Row 
    Set IE = New SHDocVw.InternetExplorer 
    urL = "http://eringcapture.jccal.org/caportal/CAPortal_MainPage.aspx" 

    For i = 2 To 2 

     fSR = SR.Range("A" & SR.Rows.Count).End(xlUp).Row + 1 
     pID = Trim(Format(.Range("A" & i).Value, "0")) ' get PID 

     If Len(pID) < 8 Then GoTo nextRow 

     IE.Visible = True 
     IE.navigate urL 

     Call WaitForIE 
     Set Doc = IE.document 
     Doc.getElementById("Iframe1").contentDocument.getElementById("RealSearchLink").Click 
     Call WaitForIE 
     Doc.getElementById("Iframe1").contentDocument.getElementById("SearchByParcel").Checked = True 

     'SearchByTB 
     'Delete the first 2 digits from the excel data (parcel ID), e.g. 22002240080330000000 (instead of 0122002240080330000000) 
     'pID = Right(pID, Len(pID) - 2) 

     Doc.getElementById("Iframe1").contentDocument.getElementById("SearchText").Value = pID 'Put id in text box 
     Doc.getElementById("Iframe1").contentDocument.getElementById("Search").Click 'search button 

     Call WaitForIE 

     fnd = False 

     If Trim(Doc.getElementById("Iframe1").contentDocument.getElementById("TotalRecFound").innerText) = "No Records Found." Then 
      For j = 1 To 6 

       pID = Left(pID, Len(pID) - 1) 

       Doc.getElementById("Iframe1").contentDocument.getElementById("SearchText").Value = pID 'Put id in text box 
       Doc.getElementById("Iframe1").contentDocument.getElementById("Search").Click 'search button 
       Call WaitForIE 

       If Trim(Doc.getElementById("Iframe1").contentDocument.getElementById("TotalRecFound").innerText) <> "No Records Found." Then 
        'Result Found 

        Stop 
        fnd = True 
        Exit For 
       End If 
      Next j 

     Else 
      'Result Found 

      Stop 
      fnd = True 
     End If 

     If Not fnd Then 
      SR.Range("A" & fSR) = "No Records Found" 
     End If 


nextRow: 
    Next i 

    IE.Quit 
    Set IE = Nothing 

End With 

MsgBox "Process Completed" 

End Sub 



Sub WaitForIE() 
While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE 
    DoEvents 
Wend 
Application.Wait Now + TimeValue("00:00:05") 
End Sub 
+0

您要导航到的页面上没有搜索框。 – sktneer

+0

@sktneer如果您点击搜索页面底部的不动产,有一个搜索框 – Rohan

回答

2

页面上有一个隐藏的Pid,其字符串格式不同。

添加到您的代码:

'SearchByTB 
    'Delete the first 2 digits from the excel data 
    '(parcel ID), e.g. 22002240080330000000 (instead of 0122002240080330000000) 
    'pID = Right(pID, Len(pID) - 2) 

    'Creating an hidden pid with string format like this: 22 00 22 4 008 033.00 
    hiddenPID = Left(pID, 2) & " " & _ 
       Mid(pID, 3, 2) & " " & _ 
       Mid(pID, 5, 2) & " " & _ 
       Mid(pID, 7, 1) & " " & _ 
       Mid(pID, 8, 3) & " " & _ 
       Mid(pID, 11, 3) & "." & _ 
       Mid(pID, 14, 2) 

    Doc.getElementById("Iframe1"). _ 
     contentDocument.getElementById("SearchText"). _ 
     Value = pID 'Put id in text box 
    Doc.getElementById("Iframe1"). _ 
     contentDocument.getElementById("HidParcelNo"). _ 
     Value = hiddenPID 'Put hidden pID in the hidden element 
    Doc.getElementById("Iframe1"). _ 
     contentDocument. _ 
     getElementById("Search").Click 'search button 

成立只是希望在POST请求时,你点击搜索框的页面一样。