Using WebBrowser controls and mshtml and streaming operations in vb.net (vb.net inline ie, removing Web pages)

Source: Internet
Author: User
Web|webbrowser control requirements are: to a Web site to crawl query results. Environment for VB.net

Starting from 0, the specific things in the. NET are not clear at first, so it's a blind search. It's Google, it's Baidu,yisou ... Random search of content has. NET IE, split Web page. NET, inline IE and so on. It's not long before you know WebBrowser this control.

Which is helpful to me. The larger article is http://www.microsoft.com/china/msdn/Archives/workshop/scrape.asp

This is just the VB environment introduced here. NET doesn't make much difference, don't laugh! I started looking for Shdocvw.dll and Mshtml.dll to add a quote. Because everyone says WebBrowser. and. NET is written in Microsoft Web browsers ..

Follow the above article to practice first!

Don't talk nonsense.

First make an input box, and a button for input information, and submit information.

In the Click event of the button, write:

Dim PostData as String () = {"searchtext=" + Me.searchText.Text}
Dim strURL as String = "http://"
Dim sessionhtml as String = Postdate (strURL, PostData)
' Generate temporary files
Dim SW As StreamWriter = New StreamWriter ("D:\1.htm", False, Encoding.GetEncoding ("GB2312"))
Sw. WriteLine (sessionhtml)
Sw. Close ()
Me.AxWebBrowserFill.Navigate ("D:\1.htm")



The Postdate function is as follows:

Public Function postdate (ByVal URL As String, ByVal PostData () As String) as String

Dim Post as String = ""
' Splicing into passing variables
For all S as String in PostData
Post = = s + "&"
Next
Post = post.substring (0, Post.length-1)
Dim html as String = ""

Dim encoding as Encoding = encoding. GetEncoding ("GB2312")
Dim data as Byte () = Encoding. GetBytes (Post)
Dim myrequest as HttpWebRequest = CType (webrequest.create (URL), HttpWebRequest)
Myrequest.method = "POST"
Myrequest.contenttype = "application/x-www-form-urlencoded"
' Myrequest.contenttype = ' text/asp '
Myrequest.contentlength = data. Length
Dim newstream as Stream = Myrequest.getrequeststream ()
Newstream.write (data, 0, data.) Length)
Newstream.close ()
Dim resp as HttpWebResponse = CType (Myrequest.getresponse (), HttpWebResponse)
Dim sr as StreamReader = New StreamReader (resp. GetResponseStream (), System.Text.Encoding.GetEncoding ("GB2312"))
' Returns a string of HTML code
html = Sr. ReadToEnd ()
Sr. Close ()
return HTML

End Function

That's it.

As for the direct HTML display in the WebBrowser control, and not through the temporary file, online search is the Delphi method. and. NET seems to have no perfect solution.



Have ever tried:

' Axwebbrowserfill.navigate (sessionhtml)
' Me.AxWebBrowserFill.Document.write (sessionhtml + "Haga")
' Me.axScriptLet.url = ' about:blank ' + sessionhtml
' Me.AxWebBrowserFill.Document.write (sessionhtml)
' doc = Me.AxWebBrowserFill.Document
' Doc.body.innerHTML = sessionhtml
' Doc.write (sessionhtml)



Often just for the first time, and the middle will involve the problem of double quotes within HTML.

There are also online said in the following ways:


' Display the report content field in WebBrowser
' Dim doc as IHTMLDocument2 = CType (axwebbrowserfill.document, IHTMLDocument2)
' Dim bodyelement as IHTMLElement = CType (Doc.body, IHTMLElement)
"bodyelement.innerhtml = sessionhtml +" Haga "

And this method I have not worked!




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.