Library tutorials & articles
Interacting with the web using WebRobot v1.0
By Fernando Sanchez, published on 17 May 2006
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.
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:
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:
We set the value of each field in the next two lines, by assigning values to the InputValue property of the input objects:
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?
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?
Related articles
Related discussion
-
we search the company in India for program creation under the order
by qwe (0 replies)
-
Excel Oledb Engine and VB.NET
by bhuvannrk (0 replies)
-
VB.NET Windows: Getting Windows Message from external class without overriding WndProc
by CallMeLaNN (0 replies)
-
String size limit and array upperbound limit
by Akhtar Hussain (2 replies)
-
DataGridViewComboBoxColumn events
by bogdan (0 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum)
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
Yes it'll save a plenty of work, thanks .
That looks very nice. It'll save me plenty of work when posting a form instead of hardcoding all the fields in a webrequest! http://www.fixx.be
This is a Very Good Example.I thin its very usefull to me.
but the problem is when i try this this not work properly error occured at this line "Dim wrobot As New foxtrot.xray.WebRobot()"
it displayes "File or Assembly name System,or one of its dependancies was not found."
Please answer to me.
This thread is for discussions of Interacting with the web using WebRobot v1.0.