Dim url As String=" 網(wǎng)址"
創(chuàng)新互聯(lián)專(zhuān)注于丹寨企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站定制開(kāi)發(fā)。丹寨網(wǎng)站建設(shè)公司,為丹寨等地區(qū)提供建站服務(wù)。全流程按需求定制開(kāi)發(fā),專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)
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 ' 獲取或設(shè)置一個(gè)值,該值指示是否與
Internet資源建立持久連接。
Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream,
System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是網(wǎng)頁(yè)源代碼
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)頁(yè)地址。
Dim sr As StreamReader = New StreamReader(stream, System.Text.Encoding.UTF8)
Label1.Text = Regex.Match(sr.ReadToEnd, "回答采納率").ToString
'sr。readtoend讀取網(wǎng)頁(yè)流到末尾,即使用正則表達(dá)式從網(wǎng)頁(yè)流中提取“回答采納率”,賦值給Label1.Text ‘沒(méi)有則為空
sr.Dispose() '關(guān)閉流
End Sub'要提取什么東西用正則表達(dá)式最好
End Class
你想一邊運(yùn)行,一邊填充數(shù)據(jù),我給你出的主意是多線程,用另一個(gè)線程來(lái)Invoke數(shù)據(jù),
Thread和線程Timer(不是Form中的Timer),要是同時(shí)訪問(wèn)一塊數(shù)據(jù)注意用
SyncLock鎖
Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String
'啟動(dòng)一次具體的數(shù)據(jù)采集工作,返回采集到的HTML內(nèi)容:要求必須輸入帶://的全地址數(shù)據(jù)
On Error Resume Next
Dim Str_WebContent As String = "請(qǐng)輸入查找網(wǎng)站地址."
Dim wb As WebClient = New WebClient() '//創(chuàng)建一個(gè)WebClient實(shí)例
If mWebsiteUrl.IndexOf("://") 0 Then
'//獲取或設(shè)置用于對(duì)向 Internet 資源的請(qǐng)求進(jìn)行身份驗(yàn)證的網(wǎng)絡(luò)憑據(jù)。(可有可無(wú))
wb.Credentials = CredentialCache.DefaultCredentials
'//從資源下載數(shù)據(jù)并返回字節(jié)數(shù)組。(加@是因?yàn)榫W(wǎng)址中間有"/"符號(hào))
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 '提取出來(lái)新聞內(nèi)容,刪除Body前后的多余內(nèi)容,同時(shí)補(bǔ)充上該 Body標(biāo)記,形成完整的內(nèi)容 Str_WebContent '
End Function