gpt4 book ai didi

vba - 如何通过Excel VBA提交表单数据

转载 作者:行者123 更新时间:2023-12-03 03:29:47 25 4
gpt4 key购买 nike

我正在尝试输入包裹 ID:220022400803300 并尝试获取结果,但即使将包裹 ID 放入搜索框中并单击提交按钮后,它也没有返回任何结果。

任何人都可以帮我解决这个问题吗?或者如果有更好的方法,请告诉我。

该网站是 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

最佳答案

页面上存在一个隐藏的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 请求即可创建。

关于vba - 如何通过Excel VBA提交表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45901834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com