當前位置:首頁 » 操作系統 » vbnet取網頁源碼

vbnet取網頁源碼

發布時間: 2024-05-21 21:46:51

1. 如何用vb.net獲得網頁的源代碼

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就是網頁源代碼

2. VB.NET如何使用正則表達式讀取網頁源碼中的指定內容

<divclass="cont">[sS]*?href=["']?([^"']*)["']?[sS]*?title=["']?([^"]*)["']?

3. VB.NET 不使用控制項獲取某網頁源代碼

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyClient As Net.WebClient = New Net.WebClient
Dim MyReader As New System.IO.StreamReader(MyClient.OpenRead("http://wap..com"), System.Text.Encoding.Default)
Dim MyWebCode As String = MyReader.ReadToEnd
Me.RichTextBox1.Text = MyWebCode
MyReader.Close()
End Sub

4. vb.net中如何利用api函數獲取網頁源代碼

Dim MyClient As WebClient = New WebClient
Dim MyReader As New System.IO.StreamReader(MyClient.OpenRead(url), System.Text.Encoding.Default) '定義新的文件流並讀取網頁文件數據,url表示需要打開的網頁地址
Dim longTxt As String = MyReader.ReadToEnd 'longtxt存儲了網頁的源碼
MyReader.Close()

5. vb 快速的取得網頁源碼和提取其中內容

如下函數可以實現你要的功能:
Function TestRegExp(ByVal myString$, ByVal myPattern$, Optional myMark$ = "gimt", Optional myRepString$)
If myString = "" Or myPattern = "" Then
TestRegExp = ""
Debug.Print "數據不能為空"
Exit Function
End If
'Create objects.
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches As MatchCollection
Dim RetStr As String

Set objRegExp = New RegExp
' 正則式
objRegExp.Pattern = myPattern
'IIf(InStr(myPattern, "s") <> 0, "", myPattern)

' 是否區分大小寫
objRegExp.IgnoreCase = IIf(InStr(LCase$(myMark), "i") > 0, True, False)

' 是否全局
objRegExp.Global = IIf(InStr(LCase$(myMark), "g") > 0, True, False)

' 是否換行
objRegExp.MultiLine = IIf(InStr(LCase$(myMark), "m") > 0, True, False)
If objRegExp.Test(myString) Then
If InStr(myMark, "r") > 0 Then
Debug.Print "正在替換"
RetStr = objRegExp.Replace(myString, myRepString)
Debug.Print IIf(RetStr <> "", "替換結果" & Left(RetStr, 10), "沒搜索到可替換字元")
Else
Debug.Print "正在搜索"
Set colMatches = objRegExp.Execute(myString) ' Execute search.
'MsgBox colMatches.Count
For Each objMatch In colMatches ' Iterate Matches collection.
'RetStr = RetStr & objMatch.FirstIndex
RetStr = RetStr & objMatch.Value & vbCrLf
Next
Debug.Print IIf(RetStr <> "", "搜索結果" & Left(RetStr, 10), "沒搜索到匹配結果")
End If
Else
RetStr = ""
Debug.Print "沒找到任何匹配結果,請檢查正則式的是否正確"
End If
TestRegExp = RetStr
End Function

6. vb.net源碼網站

洪恩在線:http://www.hongen.com/pc/program/codedown/vbcode/
天新網:http://www.21tx.com/src/vb/
VB:http://www.21tx.com/src/vb/

熱點內容
jquery代碼加密 發布:2024-11-27 03:54:51 瀏覽:593
數字密碼人格是什麼原理 發布:2024-11-27 03:46:34 瀏覽:426
華為怎麼看手機的配置 發布:2024-11-27 03:27:42 瀏覽:381
php函數作用域 發布:2024-11-27 03:26:11 瀏覽:176
pythonasteval 發布:2024-11-27 03:21:14 瀏覽:563
電腦伺服器機什麼意思 發布:2024-11-27 03:18:59 瀏覽:837
本地存儲是否允許 發布:2024-11-27 03:08:02 瀏覽:411
adc的電腦密碼是多少 發布:2024-11-27 03:01:54 瀏覽:965
會員管理系統php 發布:2024-11-27 02:15:41 瀏覽:235
企業php網站系統 發布:2024-11-27 02:14:14 瀏覽:254