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

vbnet獲取網頁源碼

發布時間: 2022-09-06 01:46:10

① 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()

② 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

③ VB:如何通過VB獲取某個網站的所有頁面源代碼

兩種實現方式:
1、先用WebBrowser控制項、iNet控制項或xmlhttp組件獲取網站首頁代碼(這個網上有一大堆介紹,就不啰嗦了),然後分析代碼,找出其中的超鏈接,然後再逐個獲取其頁面代碼,這里要注意的是,要區分外鏈和內鏈,外鏈就不要去獲取代碼了(否則的話如果網站上有個網路的鏈接,那麼你的程序就要去獲取網路的頁面了);另外還要控制獲取的層數(比如說一級子頁面是第二層,二級子頁面是第三層),否則的話遇到大型網站你的程序很可能進入死循環。
2、利用瀏覽器的緩存來獲取,主要是IE的緩存。windows系統有專門的對IE緩存進行讀寫操作的API函數。要想獲取某個網站的源碼,可以用IE打開這個網站,然後把裡面的鏈接都手工點擊一遍,使頁面代碼能被IE自動放入緩存文件夾中即可。當然,如果網站比較大,這個過程可能會比較繁復。然後再通過程序遍歷IE的整個緩存系統,把與該網站相關的所有資源都提取出來。通過這種方法,不但可以提取HTML代碼,還有js代碼、css代碼,以及頁面上的所有圖片、動畫、視頻等資源。我個人比較喜歡這種方法。

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

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

⑤ 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

⑥ 請問如何用VB獲取網頁源碼

使用Inet控制項獲取網頁源碼。

Internet Transfer 控制項實現了兩種廣泛使用的 Internet 協議: 超文本傳送協議(HyperText Transfer
Protocol)(HTTP) 和文件傳送協議(File Transfer Protocol) (FTP)。使用 Internet Transfer
控制項可以通過 OpenURL 或 Execute 方法連接到任何使用這兩個協議的站點並檢索文件。

PrivateSubCommand1_Click()
DimstrhtmlAsString
DimSTRURLAsString
STRURL="http://www..com"
strhtml=Inet1.OpenURL(STRURL)
Text1=strhtml
EndSub

⑦ 如何抓取完全展開後的網頁源代碼 VB.NET

如果是不需要載入的網頁,直接讀HTML即可;如果有載入發生,可能需要模擬一下ajax。提供一下示例網頁?

⑧ 如何用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就是網頁源代碼

⑨ 如何用vb.net獲取網頁源代碼

使用webbrowser控制項來載入網頁,然後再
Private
Sub
WebBrowser
1_DocumentCompleted下通過使用WebBrowser1.Document.Body.
InnerHtml
來獲取網頁的源代碼,或使用
WebBrowser1.Document.Body.InnerText來獲取網頁中的文本。之後可以通過字元串控制指令或者
正則表達式
來精確獲取到你所需的數據。

熱點內容
c語言延時1ms程序 發布:2025-05-12 15:01:30 瀏覽:160
動物園靈長類動物配置什麼植物 發布:2025-05-12 14:49:59 瀏覽:728
wifi密碼設置什麼好 發布:2025-05-12 14:49:17 瀏覽:143
三位數乘兩位數速演算法 發布:2025-05-12 13:05:48 瀏覽:390
暴風影音緩存在哪裡 發布:2025-05-12 12:42:03 瀏覽:535
access資料庫exe 發布:2025-05-12 12:39:04 瀏覽:623
五開的配置是什麼 發布:2025-05-12 12:36:37 瀏覽:359
加密ovpn 發布:2025-05-12 12:01:55 瀏覽:45
python練手項目 發布:2025-05-12 11:14:07 瀏覽:124
壓縮聽算音頻 發布:2025-05-12 10:58:12 瀏覽:801