vb.net2008, 网上找的,网页没加载完可能会出错
在安福等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站设计 网站设计制作按需规划网站,公司网站建设,企业网站建设,品牌网站制作,成都全网营销,外贸网站制作,安福网站建设费用合理。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("")
End Sub
Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
Dim urlNew
e.Cancel = True
urlNew = WebBrowser1.Document.ActiveElement.GetAttribute("href")
WebBrowser1.Navigate(urlNew)
End Sub
End Class
1)使用MICROSOFT INTERNET TRANSFER CONTROL的,代码如下:
Dim strhtml As String
Dim STRURL As String
STRURL=""
strhtml = Inet1.OpenURL(STRURL)
2)用System.Net命空间下的HttpWebRequest来取得,代码如下:
Dim url As String=" " ' 网址
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpReq.Method = "GET"
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = False ' 获取或设置一个值,该值指示是否与 Internet资源建立持久连接。
Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream,
System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码.
Dim c
Private Sub Form_Load()
URL = ""
c = 0
WebBrowser1.Navigate URL
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If c = 1 Then Exit Sub '这个是为了防止这个过程无限执行下去
c = c + 1
tmp = WebBrowser1.Document.body.innerhtml
tmp = Replace(tmp, "88753967", "好玩吗?")
WebBrowser1.Document.body.innerhtml = tmp
End Sub
如下两种方法,
1,
采用默认的浏览器打开FTP站点,不需要知道IE在什么地方,建议采用。
Shell("rundll32
url.dll
FileProtocolHandler
")
2,采用IE打开,只要更改为你的ie路径就可以了。不建议使用这个方法。
Shell("C:\Program
Files\Internet
Explorer\iexplore.exe
")
使用webbrowser控件来加载网页,然后再
Private
Sub
WebBrowser
1_DocumentCompleted下通过使用WebBrowser1.Document.Body.
InnerHtml
来获取网页的源代码,或使用
WebBrowser1.Document.Body.InnerText来获取网页中的文本。之后可以通过字符串控制指令或者
正则表达式
来精确获取到你所需的数据。
Dim url As String=" 网址"
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpReq.Method = "GET"
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = False ' 获取或设置一个值,该值指示是否与
Internet资源建立持久连接。
Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream,
System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码