Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String
成都創(chuàng)新互聯(lián)公司從2013年創(chuàng)立,先為涇縣等服務(wù)建站,涇縣等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為涇縣企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
'啟動一次具體的數(shù)據(jù)采集工作,返回采集到的HTML內(nèi)容:要求必須輸入帶://的全地址數(shù)據(jù)
On Error Resume Next
Dim Str_WebContent As String = "請輸入查找網(wǎng)站地址."
Dim wb As WebClient = New WebClient() '//創(chuàng)建一個WebClient實例
If mWebsiteUrl.IndexOf("://") 0 Then
'//獲取或設(shè)置用于對向 Internet 資源的請求進行身份驗證的網(wǎng)絡(luò)憑據(jù)。(可有可無)
wb.Credentials = CredentialCache.DefaultCredentials
'//從資源下載數(shù)據(jù)并返回字節(jié)數(shù)組。(加@是因為網(wǎng)址中間有"/"符號)
Dim pagedata As Object = wb.DownloadData(mWebsiteUrl)
'//轉(zhuǎn)換字符
If mWebsiteType Then
Str_WebContent = Encoding.Default.GetString(pagedata)
Else
Str_WebContent = Encoding.UTF8.GetString(pagedata)
End If
End If
Return Str_WebContent '提取出來新聞內(nèi)容,刪除Body前后的多余內(nèi)容,同時補充上該 Body標(biāo)記,形成完整的內(nèi)容 Str_WebContent '
End Function
Imports System.Net
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim stream As IO.Stream = WebRequest.Create(UrlAdress).GetResponse().GetResponseStream()
'注意urladress為你上面的網(wǎng)頁地址。
Dim sr As StreamReader = New StreamReader(stream, System.Text.Encoding.UTF8)
Label1.Text = Regex.Match(sr.ReadToEnd, "回答采納率").ToString
'sr。readtoend讀取網(wǎng)頁流到末尾,即使用正則表達式從網(wǎng)頁流中提取“回答采納率”,賦值給Label1.Text ‘沒有則為空
sr.Dispose() '關(guān)閉流
End Sub'要提取什么東西用正則表達式最好
End Class
(轉(zhuǎn)自網(wǎng)絡(luò))
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
WebBrowser1.Navigate("")
End Sub
Private Sub WebBrowser1_DocumentTitleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.DocumentTitleChanged
Me.Text = WebBrowser1.Document.Url.ToString
End Sub
Dim gs() As String = (From mt As HtmlElement In WebBrowser1.Document.Links Select System.Text.RegularExpressions.Regex.Match(mt.OuterHtml, "http://[^\x22 ]+").Value).ToArray