Click to See Complete Forum and Search --> : Web page interaction


nittnitt
October 14th, 2009, 07:45 AM
Hi.
I'm trying to make an application which will log me into a site and read the text of the site and display a certain part of that text in my form.

I'm stuck at the login, its a .php page with 2 text boxes, 1 check box and 1 button.Is there any way to manipulate those objects by using controls in my form?

HanneSThEGreaT
October 14th, 2009, 08:43 AM
A WebBrowser component would be the best suited control for this purpose :)

nittnitt
October 14th, 2009, 08:57 AM
I'm using it but cant figure out how to "WebBrowser1.TextBox1.Text = Me.TextBox1.text" :P

HanneSThEGreaT
October 14th, 2009, 09:35 AM
To obtain text from the WebPage itself, you would need to use the .DocumentText property of the WebBrowser control.

To get text from a TextBox on a webpage, you would need to know the ID / Name of that particular TextBox on the page. If you know that, you could use the GetElementById method to get the text within that textbox.

nittnitt
October 14th, 2009, 10:08 AM
I did this to get the text from the page Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Label1.Text = Me.WebBrowser1.Document.Body.InnerText
End Sub

the name of the textbox in the web page is "vb_login_password" and i need it to grab the text from the textbox in my form couse the webbrowser is visible = false

HanneSThEGreaT
October 14th, 2009, 11:11 AM
Then something like this would work for you :
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
Dim ValueOfControl = ControlToLookFor.GetAttribute("value")

TextBox1.Text = ValueOfControl

nittnitt
October 14th, 2009, 11:29 AM
this gets the text from the web browser textbox and puts it in the form textbox, while i need it to get the text from the form textbox and put it in the web browser text box

HanneSThEGreaT
October 14th, 2009, 11:38 AM
Seems I misunderstood :blush:

It is still the same principle, instead of using GetAttirbute, use SetAttribute, like so :
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
Dim ValueOfControl = ControlToLookFor.SetAttribute("value", TextBox1.text)

Is that what you wanted ¿ :)

nittnitt
October 14th, 2009, 12:02 PM
ControlToLookFor.SetAttribute("value", TextBox1.Text)
this part gives me an error

HanneSThEGreaT
October 15th, 2009, 12:39 AM
Sorry it has to be :
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
ControlToLookFor.SetAttribute("value", TextBox1.text) ' Or whatever your Form's textbox is named

Just took the previous code and modified, without reading it much :p - It happens :D

nittnitt
October 15th, 2009, 07:47 AM
Awesome worked perfectly
now i have 1 button which does not have a name, this is the souce:
<input type="submit" class="button" value="Log in" tabindex="104" title="Title Text" accesskey="s" />

how do u click it when i click on the button in my form?

P.S. i know almost nothing about html

HanneSThEGreaT
October 15th, 2009, 08:09 AM
On second thought rather change that to :
<input type="submit" ID = "Submit" class="button" value="Log in" tabindex="104" title="Title Text" accesskey="s" />

As all browsers are not create equal...

HanneSThEGreaT
October 15th, 2009, 08:11 AM
Well, it seems you have 2 options :)

By default, the Submit button is the default button, meaning, when you press enter, it will also work, like an AcceptButton on your form. So, you could use :
SendKeys.Send("{ENTER}")

May not work though, as I understand, your browser is not "visible" ¿

Second option.

Use InvokeMember("Click"), like this :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim ControlToLookFor As HtmlElement = WebBrowser1.Document.GetElementById("submit")

ControlToLookFor.InvokeMember("click")
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

After you have given your button an id, demonstrated in post #12

nittnitt
October 15th, 2009, 08:51 AM
well the page isnt mine so i cant change the source.
so instead of making the browser "visible = false" ive located it outside the form so its visible , and made the form border stile Fixed3D so it cannot be expanded
and used this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim PasswordField As HtmlElement = WebBrowser1.Document.GetElementById("vb_login_password")
PasswordField.Focus()
SendKeys.Send("{ENTER}")
End Sub

HanneSThEGreaT
October 15th, 2009, 08:57 AM
Good. I was under the impression this is your site & stuff :p

You're not using this for malicious purposes are you ¿ LOL! :lol:

nittnitt
October 15th, 2009, 09:00 AM
heh no, i just want my tool to login into a forum, go to the thread i need to get info from, and display certain text from that thread in one label and one LinkLabel

HanneSThEGreaT
October 15th, 2009, 09:04 AM
OK, else we're both in trouble LOL!

I'll be in bigger trouble though, as I'm a mod, and we're not allowed to violate AUP (http://www.webmediabrands.com/corporate/privacy/aup.html) :D

Good work!

Keep posting!