Interacting with the web using WebRobot v1.0

Logging in to MySpace

Let's start with a simple function that logs into MySpace and returns the HTML source of the page that you are redirected to right after login. We will be using the WebRobot component  to simplify our work.

Public Function myspacelogin(ByVal email As String, ByVal passwd As _
String) As String  
    Dim wrobot As New foxtrot.xray.WebRobot()
    wrobot.Base = "http://www.myspace.com"
    wrobot.LoadPage("/")
    Dim wform As foxtrot.xray.Form = wrobot.GetFormByName("theForm")
    Dim wemail As foxtrot.xray.Input = wform.GetFieldByName("email")
    Dim wpwd As foxtrot.xray.Input = wform.GetFieldByName("password")
    wemail.InputValue = email
    wpwd.InputValue = passwd
    wrobot.SubmitForm(wform)
    Return wrobot.HTMLSource
End Function


The function creates a new instance of the foxtrot.xray.WebRobot class, fetches the root page of the site, and then it starts looking for a form. The line:

Dim wform As foxtrot.xray.Form = wrobot.GetFormByName("theForm")

retrieves the form named "theForm" into a foxtrot.xray.Form object. This object allows us to manipulate the form, set values, and even submit the form when we are ready.

The next two lines, use the GetFieldByName method to obtain a form field object, which we will manipulate later:

Dim wemail As foxtrot.xray.Input = wform.GetFieldByName("email")
Dim wpwd As foxtrot.xray.Input = wform.GetFieldByName("password")

We set the value of each field in the next two lines, by assigning values to the InputValue property of the input objects:

wemail.InputValue = email
wpwd.InputValue = passwd


Finally, we submit the form, by using the SubmitForm metod of the foxtrot.xray.WebRobot class, and return the HTML source of the page fetched after the form was submitted.

Easy, No?

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe