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

热点内容
存储权限在哪里打开 发布:2025-04-06 01:58:23 浏览:424
gcc编译时选项太长 发布:2025-04-06 01:47:50 浏览:248
python文件剪切 发布:2025-04-06 01:24:12 浏览:10
打火车轮胎解压 发布:2025-04-06 01:08:13 浏览:652
eclipse修改源码 发布:2025-04-06 01:01:43 浏览:657
安卓怎么电话录音 发布:2025-04-06 00:52:27 浏览:81
linuxtomcat端口占用 发布:2025-04-06 00:50:38 浏览:710
线性规划python 发布:2025-04-06 00:49:12 浏览:297
安卓在哪里下载游戏最好 发布:2025-04-06 00:41:06 浏览:685
pythoncmd怎么运行 发布:2025-04-06 00:19:27 浏览:500