vb.net获取网页 vbs获取网页源代码

求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 如何获取当前浏览器的网址(转自网络)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
WebBrowser1.Navigate("")
End Sub
Private Sub WebBrowser1_DocumentTitleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.DocumentTitleChanged
Me.Text = WebBrowser1.Document.Url.ToString
End Sub
如何用vb.net获取网页源代码使用webbrowser控件来加载网页,然后再
Private
Sub
WebBrowser
1_DocumentCompleted下通过使用WebBrowser1.Document.Body.
InnerHtml
来获取网页的源代码,或使用
WebBrowser1.Document.Body.InnerText来获取网页中的文本 。之后可以通过字符串控制指令或者
正则表达式
来精确获取到你所需的数据 。
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
ReturnStr_WebContent'提取出来新闻内容,删除Body前后的多余内容,同时补充上该 Body标记,形成完整的内容Str_WebContent'
End Function
vb.net如何获取网页的cookie这个问题有点意思,但题主表意不明 , 确切的说应该分Web端和客户端两种情况 。
想来问到这个问题的不应该是开发Web端的,说说客户端的吧:
1、HttpWebRequest.CookieContainer
Cookies通过HttpResponse传给客户端,通过HttpRequest传回服务端,因此你可以
设置Response.Cookies集合的值修改Cookie
1
Response.Cookies("MyCookie")("Data") = myCookie
通过读取Request.Cookies集合的值得到Cookies的值
1
myCookie =Request.Cookies("MyCookie")("Data")""
2、本人自编的一个函数,放到一个模块里直接调用即可:
Dim myCookie As String
Public Function LoginAnGetCookie(ByRef sUser As String, ByRef sPass As String) As String()
On Error Resume Next
REM 登录网站并获得cookie
Dim url As String = "网站地址"
Dim postData As String = "sUser="sUser"sPass="sPass '假设传值的是这样的,实际中可用Fiddler抓取 。
Dim wc As System.Net.WebClient = New System.Net.WebClient
Rem wc.Headers.Add("Cookie", myCookie)'可讲第一次获得的Cookie赋值给myCookie,然后在此处传值给网站即可
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
wc.Headers.Add("UserAgent", "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10)")
Dim sHtml As String = wc.UploadString(url, "POST", postData)
Dim arrAllKeys() As String = wc.ResponseHeaders.AllKeys
Dim sCookies As String = "Set-Cookie"
For i As Integer = 0 To arrAllKeys.Length - 1
If arrAllKeys(i).Equals("Set-Cookie") Then sCookies = wc.ResponseHeaders.Get(i)
Next i
Return New String() {sHtml, sCookies} '返回二维数组,其中LoginAnGetCookie(0)是网页源代码,LoginAnGetCookie(1)是登录后的Cookie
End Function
如何用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获取网页 vbs获取网页源代码】关于vb.net获取网页和vbs获取网页源代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读