vb.netget网页,vbnet fileget

如何用vb.net获得网页的源代码

Dim url As String=" 网址"

网站的建设创新互联专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为自上料搅拌车等企业提供专业服务。

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读取网页内容写法

Imports System.Net

Imports System.IO

Imports System.Text.RegularExpressions

Public Class Form1

Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim stream As IO.Stream = WebRequest.Create(UrlAdress).GetResponse().GetResponseStream()

'注意urladress为你上面的网页地址。

Dim sr As StreamReader = New StreamReader(stream, System.Text.Encoding.UTF8)

Label1.Text = Regex.Match(sr.ReadToEnd, "回答采纳率").ToString

'sr。readtoend读取网页流到末尾,即使用正则表达式从网页流中提取“回答采纳率”,赋值给Label1.Text ‘没有则为空

sr.Dispose() '关闭流

End Sub'要提取什么东西用正则表达式最好

End Class

VB.NET 如何获取网页中的数据

Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String

'启动一次具体的数据采集工作,返回采集到的HTML内容:要求必须输入带://的全地址数据

On Error Resume Next

Dim Str_WebContent As String = "请输入查找网站地址."

Dim wb As WebClient = New WebClient() '//创建一个WebClient实例

If mWebsiteUrl.IndexOf("://") 0 Then

'//获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。(可有可无)

wb.Credentials = CredentialCache.DefaultCredentials

'//从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)

Dim pagedata As Object = wb.DownloadData(mWebsiteUrl)

'//转换字符

If mWebsiteType Then

Str_WebContent = Encoding.Default.GetString(pagedata)

Else

Str_WebContent = Encoding.UTF8.GetString(pagedata)

End If

End If

Return Str_WebContent '提取出来新闻内容,删除Body前后的多余内容,同时补充上该 Body标记,形成完整的内容 Str_WebContent '

End Function


网站名称:vb.netget网页,vbnet fileget
文章网址:http://pwwzsj.com/article/hopecc.html