[help]GetElement

Posts 1–4 of 4 · Page 1 of 1
[help]GetElement
Hi,

Can please sombody write a script so me program gets this "value"

<param name="movie" value="http://games2.spele.nl/swf/1/9/0/8/1/0.swf" />

I tested thiss

webbrowser1.document.getelementbyid("movie").getat tribude("value")

But it doenst works

Can you or sombody help me thnx
is this a textbox or label ? anyways try this
Code:
 /your text box or string here\ WebBrowser1.Document.All("ID").GetAttribute("value")
Use a stringbetween function(see snippets) or google.
I'm not sure if this is the most efficient way, but it's a method you could use.

(NOTE: When I was writing this function I tried to make it as broad as possible, you will likely need to fine tune it to suit your specific needs.)

Okay first, we need to get the page source of the page you're trying to extract info from, here's a little function that can retrieve the page source for you:

[php]
Private Function GetPageSource(ByVal URl As String) As String
Dim PageSource As String = ""

Try
Dim webReq As HttpWebRequest = WebRequest.Create(URl)
Dim webResponse As HttpWebResponse = webReq.GetResponse

Using sRead As New StreamReader(webResponse.GetResponseStream)
PageSource = sRead.ReadToEnd
End Using

Catch ex As Exception
MsgBox("error with source")

End Try

Return PageSource

End Function
[/php]

Okay now that we can get the source, we need to extract the text between two point, here's a function I just wrote up then specifically for this to easily obtain text between two points:

[php]
Private Function ExtractLine(ByVal WebPage As String, ByVal IndexOnLine As String, ByVal finalIndex As String)

Dim Extracted As String = ""
Dim TempFile As String = My.Computer.FileSystem.GetTempFileName & Rnd() * 99999 & ".txt"
My.Computer.FileSystem.WriteAllText(TempFile, GetPageSource(WebPage), False)

Using sReader As New StreamReader(TempFile)
Do Until sReader.EndOfStream
Dim CurrentLine As String = sReader.ReadLine
If CurrentLine.Contains(IndexOnLine) Then
Dim LIO As Integer = CurrentLine.LastIndexOf(finalIndex)
Dim FI As Integer = CurrentLine.IndexOf(IndexOnLine) + IndexOnLine.Length
Extracted = CurrentLine.Substring(FI, LIO - FI)
End If
Loop
End Using

Return Extracted

End Function
[/php]

Okay once you've added that function in, you need to call it somewhere. I.e from a button_click event:

[php]
Dim extractedInfo As String = ExtractLine("http://www.example.com/blah.aspx", "<param name=""movie""value=", " />")
MsgBox(extractedInfo)
[/php]

In this case the messagebox will say:

Code:
 "http://games2.spele.nl/swf/1/9/0/8/1/0.swf"
I hope that helps you a bit, if you have questions feel free to ask.

First post, yay!
Posts 1–4 of 4 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?