如何使用 Visual Basic 以编程方式单击 Google 表单上的 "Submit"?

How do I programmatically click "Submit" on a Google form using Visual Basic?

我正在编写 A.I。在 Visual Basic 中,当它不知道用户输入的内容时,它将把用户的输入发送到 Google 表单中,如果他们选择加入,它会在后台自动提交。

但是,我已经努力让它工作好几个小时了,因为每当我尝试在 Visual Basic 中引用该按钮时,我都会收到一个空异常。

我试图通过它的 class 来引用按钮,但显然我仍然 运行 进入空异常错误。在尝试查找按钮之前,我已验证 webBrowser 控件正在浏览页面。我希望不会有任何错误,并且可以成功提交表单。

wbFeedback.Navigate("https://docs.google.com/forms/d/e/. . . . . ./viewform?usp=pp_url&entry.1619369433=" + tbInput.Text.Replace(" ", "%20"))

tbInput 是一个文本框,用户可以在其中输入他们的问题进行处理。

这是提交按钮的代码:

<div role="button" class="uArJ5e UQuaGc Y5sE8d VkkpIf NqnGTe M9Bg4d" jscontroller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;" jsshadow="" jsname="M2UYVd" tabindex="0">
<div class="Fvio9d MbhUzd" jsname="ksKsZd"></div>
<div class="e19J0b CeoRYc"></div>
<span jsslot="" class="l4V7wb Fxmcue">
<span class="NPEfkd RveJvd snByac">Submit</span>
</span>
</div>

我得到以下结果:

Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Net
Imports System.Windows.Forms.Timer
Imports System.Collections.Specialized

tmrFeedbackSubmissionSuccess.Interval = 2000 ' Remove if you don't want to use timers to display a label temporarily
tmrFeedbackSubmissionFailed.Interval = 10000 ' Remove if you don't want to use timers to display a label temporarily

Dim client As New WebClient
Dim keyValue As New NameValueCollection
Dim postdata As String
Dim displayError As Boolean = False

lblFeedbackSubmission.ForeColor = Color.ForestGreen
lblFeedbackSubmission.Text = "Sending..."
lblFeedbackSubmission.Visible = True

postdata = tbInput.Text.ToString()
keyValue.Add("entry.xxxxxxxxxx", postdata)
'keyValue.Add("entry.xxxxxxxxxx", postdata)
'keyValue.Add("entry.xxxxxxxxxx", postdata)

' You can add more entries, I only needed one in my case because there was only one input field on the form

Try
    client.UploadValues("https://docs.google.com/forms/u/0/d/e/. . . . . ./formResponse", "POST", keyValue)

Catch ex As WebException
    lblFeedbackSubmission.ForeColor = Color.Red
    lblFeedbackSubmission.Text = String.Format("Error: {0}", ex.Message)
    tmrFeedbackSubmissionFailed.Start() ' Remove if you don't want to use timers to display a label temporarily
    displayError = True
End Try

If displayError = False Then
    lblFeedbackSubmission.Text = "Sent Successfully!"
    tmrFeedbackSubmissionSuccess.Start() ' Remove if you don't want to use timers to display a label temporarily
End If