wildcard76
asked on
How to convert httpWebResponse into mshtml.HTMLDocument
Hi everybody,
I have something like
Private doc As New mshtml.HTMLDocument
Dim sStream As Stream
Dim URLReq As HttpWebRequest
Dim URLRes As HttpWebResponse
URLReq = WebRequest.Create(v_crawlU RL)
URLRes = URLReq.GetResponse()
sStream = URLRes.GetResponseStream()
Dim sr As New StreamReader(sStream)
Dim cont As String = sr.ReadToEnd
now I have the content of the page in the cont variable but I'm stuck here. How do I get it into a mshtml.HTMLDocument object ?
Should not be that hard...
Thanks in advance
Regards
I have something like
Private doc As New mshtml.HTMLDocument
Dim sStream As Stream
Dim URLReq As HttpWebRequest
Dim URLRes As HttpWebResponse
URLReq = WebRequest.Create(v_crawlU
URLRes = URLReq.GetResponse()
sStream = URLRes.GetResponseStream()
Dim sr As New StreamReader(sStream)
Dim cont As String = sr.ReadToEnd
now I have the content of the page in the cont variable but I'm stuck here. How do I get it into a mshtml.HTMLDocument object ?
Should not be that hard...
Thanks in advance
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
actually images property is also empty...
raising points btw...
regards
raising points btw...
regards
ASKER
ok when I debug and examine the document after m_document = DirectCast(doc.createDocum entFromUrl (m_url, vbNullString), mshtml.HTMLDocument) is executed, i noticed the below errors...
baseUrl <error: an exception of type: {System.NotImplementedExce ption} occurred> String
enableDownload <error: an exception of type: {System.NotImplementedExce ption} occurred> Boolean
frames <error: an exception of type: {System.InvalidCastExcepti on} occurred> mshtml.FramesCollection
IHTMLDocument2_frames <error: an exception of type: {System.InvalidCastExcepti on} occurred> mshtml.FramesCollection
IHTMLDocument2_location <error: an exception of type: {System.InvalidCastExcepti on} occurred> mshtml.HTMLLocation
IHTMLDocument2_parentWindo w <error: an exception of type: {System.InvalidCastExcepti on} occurred> mshtml.IHTMLWindow2
IHTMLDocument2_Script <error: an exception of type: {System.InvalidCastExcepti on} occurred> Object
and several others...
title "Google" String
is present as well which means the sub actually connects to the url and receives some data...
regards
baseUrl <error: an exception of type: {System.NotImplementedExce
enableDownload <error: an exception of type: {System.NotImplementedExce
frames <error: an exception of type: {System.InvalidCastExcepti
IHTMLDocument2_frames <error: an exception of type: {System.InvalidCastExcepti
IHTMLDocument2_location <error: an exception of type: {System.InvalidCastExcepti
IHTMLDocument2_parentWindo
IHTMLDocument2_Script <error: an exception of type: {System.InvalidCastExcepti
and several others...
title "Google" String
is present as well which means the sub actually connects to the url and receives some data...
regards
.NET version?
Bob
Bob
ASKER
1.1
ASKER
1.1 4322 to be precise
What type of application are you running from? WinForms? ASP.NET?
Bob
Bob
ASKER
it is a winforms application...
ASKER
I've experienced something before, while I was using a axWebBrowser control on a form, when I used the navigate2 method on the control when the form is not visible, I had a cominvalidstate exception, which I corrected by simply showing the form before navigaitng... can it be something similar... because there's no visible controls etc... I know it's a far shot:)
ASKER
found it...
Dim oDoc As New mshtml.HTMLDocument
Dim iDoc As mshtml.IHTMLDocument2 = oDoc
'write to the IHTMLDocument2
iDoc.write(cont)
iDoc.close()
'get it back to an HTMLDocument
oDoc = iDoc
does the trick....
thanks for the help...
Dim oDoc As New mshtml.HTMLDocument
Dim iDoc As mshtml.IHTMLDocument2 = oDoc
'write to the IHTMLDocument2
iDoc.write(cont)
iDoc.close()
'get it back to an HTMLDocument
oDoc = iDoc
does the trick....
thanks for the help...
Ok, so next time I ask if you want to use WebBrowser control. ;) That was code that you could use (if it worked), that you only need a URL, and not any ActiveX control, running through interoperability.
Bob
Bob
ASKER
the class seems really solid and substantial
but when I try to do something like
Dim ht As New HtmlDocument("http://www.google.com")
Dim a As HtmlAnchor
For Each a In ht.Anchors
MessageBox.Show(a.HRef)
Next
anchors property always returns empty regardless of the url i provide.
what may i be doing wrong ?
regards