Yogesh_Agarwal
asked on
Web browser manipulation
hi,
hi,
I am stripping few tags in html file and then assigning that html string to documenttext property of webbrowser. i can successfully do it, but when i use webbroswer1.document.GetEl ementById( xx) i am getting invalide type cast exception error.. can someone clear out my problem? even if i use any of webbrowser document property i am getting invalidtypecast exception..
hi,
I am stripping few tags in html file and then assigning that html string to documenttext property of webbrowser. i can successfully do it, but when i use webbroswer1.document.GetEl
That doesn't explain enough about why you are getting that exception.
ASKER
i am getting source by usiung httpwebreqest, htepwebrespnse and converting stream to string then stripping html tags and displaying it in webbrowser.. then doing manipulation like webbrowser1.document.getEl ementby ID(xxx).. but i am getting error only when i use webbrowser.document properties... Error Msg = Specified type cast is not valid.
Could you show me a little code that describes this problem?
ASKER
HOPE THE ABOVE CODE CLEARS U..
Dim wreq As HttpWebRequest
Dim wres As HttpWebResponse
Dim str as string ="http://www.searchenginemarketingpro.com"
wreq = HttpWebRequest.Create(str)
wreq.Method = "Post"
wres = wreq.GetResponse
Dim sr As StreamReader
sr = New StreamReader(wres.GetResponseStream)
str = sr.ReadToEnd
str = replacetags(str) 'This is a function which replaces all html tags and return a string. this part is correct as it displayes correct thing in webbrowser.
webbrowser1.DocumentText = str
webbrowser1.update()
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input") 'HERE I AM GETTING INVALID TYPE CAST EXCEPTION ERROR....
1) If you are using the WebBrowser control, I am confused why you don't just use the WebBrowser.Navigate(url) method.
2) I like to use the Microsoft.mshtml namespace to parse the HTML, which would require the WebBrowser.Document.DomDoc ument.
3) Does the <input> element have an ID?
2) I like to use the Microsoft.mshtml namespace to parse the HTML, which would require the WebBrowser.Document.DomDoc
3) Does the <input> element have an ID?
ASKER
1) If you are using the WebBrowser control, I am confused why you don't just use the WebBrowser.Navigate(url) method.
############ Due to nested frames and few elements in webpage that really sucks to load, cracks the software... creates huge delay..
2) I like to use the Microsoft.mshtml namespace to parse the HTML, which would require the WebBrowser.Document.DomDoc ument.
########### Y cant we do it by Regex?
3) Does the <input> element have an ID?
########## its just a sample code... ya they have...
############ Due to nested frames and few elements in webpage that really sucks to load, cracks the software... creates huge delay..
2) I like to use the Microsoft.mshtml namespace to parse the HTML, which would require the WebBrowser.Document.DomDoc
########### Y cant we do it by Regex?
3) Does the <input> element have an ID?
########## its just a sample code... ya they have...
I fail to understand what the difference between using an HttpWebRequest and the WebBrowser that would cause huge delays. If you want to use Regex to parse HTML, have fun.
This code says to me that what you are doing should work.
HtmlDocument..GetElementsB yTagName Method
http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.getelementsbytagname.aspx
This code says to me that what you are doing should work.
HtmlDocument..GetElementsB
http://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument.getelementsbytagname.aspx
ASKER
cool its nice link mate.. but i don know y its not working.. :-( getting invalid type cast exception error..
Try this:
Dim test As Object = WebBrowser1.Document.GetEl ementsByTa gName("Inp ut")
Dim typeName As String = test.GetType().Name
Dim test As Object = WebBrowser1.Document.GetEl
Dim typeName As String = test.GetType().Name
ASKER
here wat is that test.gettype().Name?
i used a dead try catch finally block..
try
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetEl ementsByTa gName("Inp ut")
a:
For Each curElement As HtmlElement In theElementCollection
************************** Codings ************************** ********** ********** *****
catch ex as exception
goto a
end try
he he he.. its working..
i used a dead try catch finally block..
try
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetEl
a:
For Each curElement As HtmlElement In theElementCollection
**************************
catch ex as exception
goto a
end try
he he he.. its working..
ASKER
Dim test As Object = WebBrowser1.Document.GetEl ementsByTa gName("Inp ut")
Dim typeName As String = test.GetType().Name
mate can u please explain me this further.. how to use this?
Dim typeName As String = test.GetType().Name
mate can u please explain me this further.. how to use this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mate my code sometimes works and sometime it doesnt.. wat will be the problem? is it timing issue? if i set webbrowser1.documenttext= string1 then its invoking webbrowser_document completed event.. is there a way to prevent it?
I would check the WebBrowser.ReadyState if you think that it is a timing issue.
ASKER
it hangs the whole application if i have a while (webbrowser1.readystate <> webbrow.Complete)
Do you have an Application.DoEvents()? What is the ReadyState within the While loop?
ASKER
yeah i have but only stops the whole process.. :-(
Can you show me what you have so far?
I use WebBrowser.ReadyState a lot, and I have seen a few problems using it, but it is usually a web page problem.
I use WebBrowser.ReadyState a lot, and I have seen a few problems using it, but it is usually a web page problem.
ASKER
mate instead of using that thing(readystate and loop) can i use webbrowswer1.update() to load the page completely? most of problem that i have encountered is timing issue..
ASKER
good..
ASKER