if (browser.Document.GetElementbyID("freedompeace") != null)
// element exists..
Originally Posted by freedompeace
if (browser.Document.GetElementbyID("freedompeace") != null)
// element exists..
He's trying to use the Function GetElementByID without using a webbrowser. Basically like calling Form1.Show() without Form1...
1) If this is for your IP manager, you can try downloading the webpage's source using a WebClient and then loading the HTML/XML into an XMLDocument or whatever its called.
2) mshtml.
Originally Posted by Iamazn1
He's trying to use the Function GetElementByID without using a webbrowser. Basically like calling Form1.Show() without Form1...
1) If this is for your IP manager, you can try downloading the webpage's source using a WebClient and then loading the HTML/XML into an XMLDocument or whatever its called.
2) mshtml.
I DIDN SAY NOTHING ABOUT IP MANAGER.
Im just asking if is possible getElementbyId without a webbrowser.
Use the library Jason released few days ago. And learn string manipulation.
You can do it, but it means using a COM object called HTML Object Library. It renders text into a HTML document which you can then call getElementById...etc. IMO you should just create a custom function to find it, or as Hassan said, use my library.
[highlight=vb.net]
Private Function ReplaceMetachars(ByVal input As String) As String
Dim output As String = input
Dim chars As String = "[\+*?(|$^.)"
For Each s As String In chars
output = output.Replace(s, "\" & s)
Next
Return output
End Function
Private Function GetElementByID(ByVal ID As String, ByVal src As String) As String
Dim idPattern As String = "<([a-zA-Z]*)\s.*?id=""" & ReplaceMetachars(ID) & """[\s\S]*?</\1>"
Dim m As Match = Regex.Match(src, idPattern, RegexOptions.Compiled)
Return m.Value
End Function
[/highlight]
And after that I'd probably build a custom "Element" class to do various operations on the value so that it's similar to a HTMLElement in terms of functionality. Then I'd make the function return an "Element" instead of a raw string.
Jason, what if the tag contains numbers ?
Modified a bit to support numbers in tag:
[highlight=vbnet]Dim idPattern As String = "<([a-zA-Z0-9]*)\s.*?id=""" & ReplaceMetachars(ID) & """[\s\S]*?</\1>"[/highlight]
Originally Posted by Hassan
Jason, what if the tag contains numbers ?
Modified a bit to support numbers in tag:
[highlight=vbnet]Dim idPattern As String = "<([a-zA-Z0-9]*)\s.*?id=""" & ReplaceMetachars(ID) & """[\s\S]*?</\1>"[/highlight]
DERP, i forgot that the "h" tags have numbers. My bad. Seeing as you're using the whole character class, may as well just do
[highlight=vbnet]Dim idPattern As String = "<(\w*)\s.*?id=""" & ReplaceMetachars(ID) & """[\s\S]*?</\1>"[/highlight]
Originally Posted by Iamazn1
He's trying to use the Function GetElementByID without using a webbrowser. Basically like calling Form1.Show() without Form1...
1) If this is for your IP manager, you can try downloading the webpage's source using a WebClient and then loading the HTML/XML into an XMLDocument or whatever its called.
2) mshtml.