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

热点内容
qq空间本地上传的音乐 发布:2024-11-27 06:14:50 浏览:920
办公室云电脑服务器 发布:2024-11-27 06:11:45 浏览:26
有趣的php 发布:2024-11-27 05:58:13 浏览:960
php网页开发 发布:2024-11-27 05:56:09 浏览:956
手机密码锁忘记怎么办 发布:2024-11-27 05:54:35 浏览:153
安卓怎么获取联系人位置 发布:2024-11-27 05:53:58 浏览:49
最新云呼服务器地址 发布:2024-11-27 05:49:35 浏览:944
我的世界服务器玩家 发布:2024-11-27 05:49:20 浏览:320
python正则compile 发布:2024-11-27 05:19:05 浏览:29
数据库系统概论第四版ppt 发布:2024-11-27 04:59:52 浏览:412