我目前正在编写机器人以在某个网站上提交付款。我用简单的形式写了这一切;抓取和填充工作正常,但问题是当它通过第一次提交付款时,Web浏览器显示网页已过期。我需要帮助,以便在我付款时不会使网页过期。
Imports System.ComponentModel
Imports System.Security.Policy
Public Class Form1
Dim test As String
Dim useless As String
Dim usernme As String
Dim password As String
Dim first() As String
Dim fullname As String
Dim firstn As String
Dim lastn As String
Dim email As String
Dim full As String
Dim fulldir() As String
Dim stszip() As String
Dim adress As String
Dim city As String
Dim state As String
Dim zip As String
#Region "Page Loading Functions"
Private Property pageready As Boolean = False
Private Sub WaitForPageLoad()
AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
While Not pageready
Application.DoEvents()
End While
pageready = False
End Sub
Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
pageready = True
RemoveHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
End If
End Sub
#End Region
#Region "Page Loading Functions 2"
Private Property pageready2 As Boolean = False
Private Sub WaitForPageLoad2()
AddHandler WebBrowser2.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter2)
While Not pageready
Application.DoEvents()
End While
pageready = False
End Sub
Private Sub PageWaiter2(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If WebBrowser2.ReadyState = WebBrowserReadyState.Complete Then
pageready = True
RemoveHandler WebBrowser2.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter2)
End If
End Sub
#End Region
Dim url As String = ""
Dim pass As String
Private Sub WebBrowser1_NewWindow(sender As Object, e As CancelEventArgs) Handles WebBrowser1.NewWindow
e.Cancel = True
WebBrowser1.Navigate(WebBrowser1.StatusText)
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim links As HtmlElementCollection = WebBrowser1.Document.Links
For Each var As HtmlElement In links
var.AttachEventHandler("onclick", AddressOf LinkClicked)
Next
End Sub
Private Sub LinkClicked(sender As Object, e As EventArgs)
Dim link As HtmlElement = WebBrowser1.Document.ActiveElement
url = link.GetAttribute("href")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
WebBrowser2.ScriptErrorsSuppressed = True
WebBrowser2.Navigate("http://www.fakenamegenerator.com/")
WaitForPageLoad2()
Dim docum As HtmlElementCollection = WebBrowser2.Document.GetElementsByTagName("div")
Dim i As Integer = -1
For Each CurElement As HtmlElement In docum
If CurElement.GetAttribute("classname") = "address" Then
full = CurElement.InnerText
RichTextBox1.Text = full
End If
Next
docum = WebBrowser2.Document.GetElementsByTagName("span")
For Each CurElement2 As HtmlElement In docum
If CurElement2.GetAttribute("classname") = "value" Then
test = CurElement2.InnerText
If test.Contains("@") Then
email = test
End If
End If
Next
RichTextBox1.Text = RichTextBox1.Text + vbCrLf + email
fullname = RichTextBox1.Lines(0).ToString
first = Split(fullname, ".")
firstn = first(0)
lastn = first(1)
fulldir = Split(RichTextBox1.Lines(2).ToString, ",")
city = fulldir(0)
useless = fulldir(1)
stszip = Split(useless, " ")
state = stszip(1)
zip = stszip(2)
WebBrowser1.Document.GetElementById("username").SetAttribute("value", email)
WebBrowser1.Document.GetElementById("password").SetAttribute("value", pass)
Dim subm1 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each subm2 As HtmlElement In subm1
If subm2.GetAttribute("type") = "submit" Then
subm2.InvokeMember("click")
End If
Next
WaitForPageLoad()
MsgBox("lol")
WebBrowser1.Document.GetElementById("first-name").SetAttribute("value", firstn)
WebBrowser1.Document.GetElementById("last-name").SetAttribute("value", lastn)
Dim zipcodchk As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each zipcodch As HtmlElement In zipcodchk
If zipcodch.GetAttribute("id") = "zip_code" Then
zipcodch.SetAttribute("value", zip)
End If
Next
For Each country As HtmlElement In zipcodchk
If country.GetAttribute("id") = "fake_country" Then
country.SetAttribute("value", "US")
End If
Next
Dim fullcc() As String
fullcc = Split(TextBox1.Text, "|")
WebBrowser1.Document.GetElementById("ccn").SetAttribute("value", fullcc(0))
WebBrowser1.Document.GetElementById("month").SetAttribute("value", fullcc(1))
WebBrowser1.Document.GetElementById("year").SetAttribute("value", fullcc(2))
WebBrowser1.Document.GetElementById("cvv2_code").SetAttribute("value", fullcc(3))
WebBrowser1.Document.GetElementById("continue3").InvokeMember("click")
WaitForPageLoad()
Dim subm3 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each subm4 As HtmlElement In subm3
If subm4.GetAttribute("id") = "continue3" Then
Exit Sub
End If
Next
WebBrowser1.Document.GetElementById("572").InvokeMember("click")
WaitForPageLoad()
WebBrowser1.Document.GetElementById("without-donation").InvokeMember("click")
WaitForPageLoad()
WebBrowser1.Document.GetElementById("checkbox1").InvokeMember("click")
WebBrowser1.Document.GetElementById("checkbox1").SetAttribute("value", "No")
Dim submit3 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each pressed As HtmlElement In submit3
If pressed.GetAttribute("type") = "submit" Then
pressed.InvokeMember("click")
End If
Next
WaitForPageLoad()
WebBrowser1.Document.GetElementById("continue-receipt").InvokeMember("click")
WaitForPageLoad()
If WebBrowser1.Url.ToString.Contains("home") Then
Label1.Text = Label1.Text + 1
End If
End Sub
Private Sub GenerateString()
Dim xCharArray() As Char = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray
Dim xNoArray() As Char = "0123456789".ToCharArray
Dim xGenerator As System.Random = New System.Random()
Dim xStr As String = String.Empty
While xStr.Length < 8
If xGenerator.Next(0, 2) = 0 Then
xStr &= xCharArray(xGenerator.Next(0, xCharArray.Length))
Else
xStr &= xNoArray(xGenerator.Next(0, xNoArray.Length))
End If
End While
pass = xStr
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
WebBrowser1.Document.GetElementById("first-name").SetAttribute("value", firstn)
WebBrowser1.Document.GetElementById("last-name").SetAttribute("value", lastn)
Dim zipcodchk As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each zipcodch As HtmlElement In zipcodchk
If zipcodch.GetAttribute("id") = "zip_code" Then
zipcodch.SetAttribute("value", zip)
End If
Next
Dim fullcc() As String
fullcc = Split(TextBox1.Text, "|")
WebBrowser1.Document.GetElementById("ccn").SetAttribute("value", fullcc(0))
WebBrowser1.Document.GetElementById("month").SetAttribute("value", fullcc(1))
WebBrowser1.Document.GetElementById("year").SetAttribute("value", fullcc(2))
WebBrowser1.Document.GetElementById("cvv2_code").SetAttribute("value", fullcc(3))
WebBrowser1.Document.GetElementById("continue3").InvokeMember("click")
WaitForPageLoad()
Dim subm3 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each subm4 As HtmlElement In subm3
If subm4.GetAttribute("id") = "continue3" Then
Exit Sub
End If
Next
WebBrowser1.Document.GetElementById("572").InvokeMember("click")
WaitForPageLoad()
WebBrowser1.Document.GetElementById("without-donation").InvokeMember("click")
WaitForPageLoad()
WebBrowser1.Document.GetElementById("checkbox1").InvokeMember("click")
WebBrowser1.Document.GetElementById("checkbox1").SetAttribute("value", "No")
Dim submit3 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each pressed As HtmlElement In submit3
If pressed.GetAttribute("type") = "submit" Then
pressed.InvokeMember("click")
End If
Next
WaitForPageLoad()
WebBrowser1.Document.GetElementById("continue-receipt").InvokeMember("click")
WaitForPageLoad()
If WebBrowser1.Url.ToString.Contains("home") Then
Label1.Text = Label1.Text + 1
End If
End Sub
我遗漏了网站,如果它是网站,那么我无能为力