Reading Javascript In VB?

Posts 1–15 of 21 · Page 1 of 2
Reading Javascript In VB?
Is it possible? If so then how would i retrieve the value of something like this:
Code:
<td class="item">Total_Money_Count</td>
<td class="value">2,142</td>
Like how would i read the java code so that i could find the Value of of it via a webbrowser in a VB app
By value do you mean the displayed value as is (already) in a table, or do you mean pre calculation and call java script?

You can parse the value from the table with RegEx or use Html element collections to gather the information, if that is the case, there is no need for calling Java Script.

If you want to manipulate the javascipt itself and call using java and calling it from vb.net then you can use Page.RegisterStartupScript which if I recall is a obsolete API found in web.dll and may only work in a asp.net application with vb code behind.

By itself (in vb.net alone) the process is a little more complicated.

I could probably write a tutorial in time, but it depends on what exactly you are looking to do.

I can pretty much handle any manipulation , just need to know what you are looking to do, and if it helps others as well, the site.
If you just want to scrape the values, you can just use the WebBrowser's inbuilt functions.

Something like this for the two you've provided:

[php]
Dim item As String = (From h As HtmlElement In WebBrowser1.Document.GetElementsByTagName("td") where h.GetAttribute("className") = "item" select h.Innertext)(0)
dim value as Integer = (From x As HtmlElement In WebBrowser1.Document.GetElementsByTagName("td") where x.GetAttribute("className") = "value" and Integer.TryParse(x.InnerText) select Cint(x.InnerText))(0)
[/php]
Quote Originally Posted by Jason View Post
If you just want to scrape the values, you can just use the WebBrowser's inbuilt functions.

Something like this for the two you've provided:

[php]
Dim item As String = (From h As HtmlElement In WebBrowser1.Document.GetElementsByTagName("td") where h.GetAttribute("className") = "item" select h.Innertext)(0)
dim value as Integer = (From x As HtmlElement In WebBrowser1.Document.GetElementsByTagName("td") where x.GetAttribute("className") = "value" and Integer.TryParse(x.InnerText) select Cint(x.InnerText))(0)
[/php]
I tried a code similar to this but i could've been off by a little /
Ill play around with the code you provided and post feedback /yea
Quote Originally Posted by Bombsaway707 View Post

I tried a code similar to this but i could've been off by a little /
Ill play around with the code you provided and post feedback /yea
Okie dokie, if that still doesn't work, it could be the page in question having multiple elements with the classname "item" with the tag "td" and since I just called the first index of this, it may return incorrect results...which means better filtering would be needed. Or, just regex that shit.

If you need any more help with it just PM/VM me a link to the site and I'll see what I can do to help.
Quote Originally Posted by Jason View Post


Okie dokie, if that still doesn't work, it could be the page in question having multiple elements with the classname "item" with the tag "td" and since I just called the first index of this, it may return incorrect results...which means better filtering would be needed. Or, just regex that shit.

If you need any more help with it just PM/VM me a link to the site and I'll see what I can do to help.
Alright thanks man
Couldn't you just do it like this?
i.e(an img);
Like have a webbrowser in the form where when it loads you could do:
[php]
Private Sub WebBrowser1_DocumentCompleted(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs) Handles WebBrowser1.DocumentCompleted

Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")

For Each CurElement As HtmlElement In PageElements

Label1.Text & CurElement.GetAttribute("src")

Next

End Sub
End Class
[/php]
And the elements would go inside the label or a textbox?.
Quote Originally Posted by HiddenoO View Post
Couldn't you just do it like this?
i.e(an img);
Like have a webbrowser in the form where when it loads you could do:
[php]
Private Sub WebBrowser1_DocumentCompleted(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs) Handles WebBrowser1.DocumentCompleted

Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")

For Each CurElement As HtmlElement In PageElements

Label1.Text & CurElement.GetAttribute("src")

Next

End Sub
End Class
[/php]
And the elements would go inside the label or a textbox?.
Yes and No, I mentioned HTML Elements already, if he uses DOMS and HTML elements, he may need to check the outterhtml or innerhtml instead of the attribute or tag name. But all this is dependent on a few things, Jason has the right idea. His code (in a once over) looks sufficient.
Quote Originally Posted by NextGen1 View Post


Yes and No, I mentioned HTML Elements already, if he uses DOMS and HTML elements, he may need to check the outterhtml or innerhtml instead of the attribute or tag name. But all this is dependent on a few things, Jason has the right idea. His code (in a once over) looks sufficient.
I stuffed up my integer.Tryparse (forgot to put ", Nothing" at the end). Should look like Integer.TryParse(x.InnerText, Nothing) but yeah, can't edit it now.

Also, there are different ways of achieving the same result, but as we can't see the page HTML as a whole, we can only make educated guesses based on what we've been given by you. It may be that you need some better identifying methods because these may not narrow down the options enough, but we'll see.
It seems to be a recurring battle in alot of these threads.
I suggest VMing me the site and what you need extracted, Ill get you code.

Either case, I feel there is a lack of information. I (personally) need things as detailed as possible, Seeing as there are usually 20 + routes for every solution, and the smallest detail can make a difference in functional code and not.
Quote Originally Posted by NextGen1 View Post

I suggest VMing me the site and what you need extracted, Ill get you code.
Already told him to do that, but to me

Quote Originally Posted by NextGen1 View Post

Either case, I feel there is a lack of information. I (personally) need things as detailed as possible, Seeing as there are usually 20 + routes for every solution, and the smallest detail can make a difference in functional code and no
Exactly what I said above

In closing:

<3
Quote Originally Posted by NextGen1 View Post
It seems to be a recurring battle in alot of these threads.
I suggest VMing me the site and what you need extracted, Ill get you code.

Either case, I feel there is a lack of information. I (personally) need things as detailed as possible, Seeing as there are usually 20 + routes for every solution, and the smallest detail can make a difference in functional code and not.
Basically I think he just wants to retrieve info from a page like for instance;
If you had a VB application, and 1 label said Money Value:
And the label next to it would somehow retrieve the info form the webpage, and stay up-to-date with the value.
Like combat arms.
You could have a label say Kills:
and another label identifying the value of Kills each time the application is opened on the account using html/java.
Quote Originally Posted by HiddenoO View Post
Basically I think he just wants to retrieve info from a page like for instance;
If you had a VB application, and 1 label said Money Value:
And the label next to it would somehow retrieve the info form the webpage, and stay up-to-date with the value.
Like combat arms.
You could have a label say Kills:
and another label identifying the value of Kills each time the application is opened on the account using html/java.
We know

We're just saying the rest of the HTML on the page comes into play when creating a working solution. There is not always a general all-fit solution so we'd like to take a look at the rest of the HTML before we commit completely to an answer.
Quote Originally Posted by HiddenoO View Post
Basically I think he just wants to retrieve info from a page like for instance;
If you had a VB application, and 1 label said Money Value:
And the label next to it would somehow retrieve the info form the webpage, and stay up-to-date with the value.
Like combat arms.
You could have a label say Kills:
and another label identifying the value of Kills each time the application is opened on the account using html/java.

Thanks for the VB Lesson, I can learn so so much from you.
Thanks Again

Quote Originally Posted by NextGen1 View Post



Thanks for the VB Lesson, I can learn so so much from you.
Thanks Again

^^ This is the troof. Rich sucks at VB, he just comes here because he has an IQ of about 5 and can't grasp what the bombs is trying to do. Cut him some slack.
Posts 1–15 of 21 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?