i just wanted to make a small bot using a web browser to post comments to wordpress blogs !
well i don't know the reason but it seems that only the last url is executed ! when i load a list and start the posting the loop seems to jump to the last url !

any help please ?

Thanks !

Imports


Public Class Form1

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)



    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If (TextBox4.Text = "") Then
            MsgBox("load a list first")
        Else

            'StartPosition going throught the target.txt line by line
            Dim sFileName As String
            Dim srFileReader As System.IO.StreamReader
            Dim sInputLine As String

            sFileName = TextBox4.Text
            srFileReader = System.IO.File.OpenText(sFileName)
            sInputLine = srFileReader.ReadLine()
            Do Until sInputLine Is Nothing

                WebBrowser1.Navigate(sInputLine)

                sInputLine = srFileReader.ReadLine()

            Loop
            MsgBox(WebBrowser1.DocumentTitle)
        End If

    End Sub

    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged

    End Sub

 

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

    

    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)

    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        If (RadioButton1.Checked = True) Then
            WebBrowser1.Document.GetElementById("name").SetAttribute("value", TextBox1.Text)
            WebBrowser1.Document.GetElementById("email").SetAttribute("value", TextBox2.Text)
            WebBrowser1.Document.GetElementById("url").SetAttribute("value", TextBox3.Text)
            WebBrowser1.Document.GetElementById("words").SetAttribute("value", RichTextBox1.Text)
            WebBrowser1.Document.GetElementById("submit").InvokeMember("click")
        End If

        If (RadioButton2.Checked = True) Then
            WebBrowser1.Document.GetElementById("name").SetAttribute("value", TextBox1.Text)
            WebBrowser1.Document.GetElementById("mail").SetAttribute("value", TextBox2.Text)
            WebBrowser1.Document.GetElementById("website").SetAttribute("value", TextBox3.Text)
            WebBrowser1.Document.GetElementById("comment").SetAttribute("value", RichTextBox1.Text)
            WebBrowser1.Document.GetElementById("submit").InvokeMember("click")
        End If

    End Sub

    Private Sub Button3_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        OpenFileDialog1.InitialDirectory = "C:\"
        OpenFileDialog1.ShowDialog()
        TextBox4.Text = OpenFileDialog1.FileName

    End Sub

    Private Sub WebBrowser1_Navigated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated

    End Sub
End Class

Recommended Answers

All 7 Replies

Why would you want to do this? Sounds like spam to me.

it is for testing purpose only !

anyone can help fix this code ! i'm just getting started with coding i just want to know where was my mistake !

Thanks to all !

It is in your Do/Until loop on line 30.

Your WebBrowser does not have time to load a page, set values, and move on to the next link. The Do/Until loop probably goes through all the urls from your file before the first url even has time to load.

I would load your file into an ArrayList, send the first item(url path from file) to the WebBrowser, let it load, set values, and THEN move on to the next item in the ArrayList until the last item has been loaded.

Btw, it does seem like a spam bot, just posting multi-posts on different sites without being able to know what the content on each site already is. It could possibly be a Holidays Greetings bot, to send "Merry Christmas from..." to all of your friends. Or just simply for testing, although I do doubt as much.

thanks for your reply codeorder ,but how to make the browser wait till the url loads then move to the next line ?

...

I would load your file into an ArrayList, send the first item(url path from file) to the WebBrowser, let it load, set values, and THEN move on to the next item in the ArrayList until the last item has been loaded.

...

Use the _DocumentCompleted event for your WebBrowser, to give it time to load the page and set values, then at the end of that Sub/Event, move on to the next item/url in your list.

In a recent project, I previously had to check if a value was set in a WebBrowser's TextBox/Textarea, before moving on to loading the next page.

thats what i thought too !in the code above you will see that i use document completed event to do that ! and it didn't work !

Use the _DocumentCompleted event for your WebBrowser, to give it time to load the page and set values, then at the end of that Sub/Event, move on to the next item/url in your list.

In a recent project, I previously had to check if a value was set in a WebBrowser's TextBox/Textarea, before moving on to loading the next page.

In the _DocumentCompleted , after you set the values to a page, THEN... IN THAT SAME EVENT, load the next page as the last line of code until the last url has been used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.