当前位置:首页 » 操作系统 » 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/

热点内容
sqlserver数据库置疑 发布:2025-09-14 20:42:37 浏览:489
实参与其对应的形参各占用独立的存储单元 发布:2025-09-14 20:17:44 浏览:324
面板系统后台ftp啥意思 发布:2025-09-14 20:09:34 浏览:981
最小二乘法python 发布:2025-09-14 19:58:02 浏览:218
des算法c实现 发布:2025-09-14 19:51:50 浏览:472
mssql清空数据库数据 发布:2025-09-14 19:25:40 浏览:110
安卓机为什么越用内存越少 发布:2025-09-14 19:24:47 浏览:344
域名服务器地址多少 发布:2025-09-14 19:11:38 浏览:489
手机自学编程 发布:2025-09-14 19:11:02 浏览:528
脚本刷宝典 发布:2025-09-14 19:04:01 浏览:857