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获得网页的源代码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 ' 获取或设置一个值vb.net获取url , 该值指示是否与
Internet资源建立持久连接 。
Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream,
System.Text.Encoding.GetEncoding(-0))
Dim respHTML As String = reader.ReadToEnd() 'respHTML就是网页源代码
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怎么实现点击下载,获取文件路径并下载下载 , 直接通过url读取文件,然后Response.OutputStream.Write()数据
下面提供个下载的静态方法,是C#的,供参考:
/// summary
/// 下载文件
/// /summary
/// param name="fileName"下载的文件名称(包括扩展名)/param
/// param name="filePath"下载文件的绝对路径/param
public static void DownFile(string fileName, string filePath)
【vb.net获取url vbs获取当前路径】{
//打开要下载的文件,并把该文件存放在FileStream中
System.IO.FileStream Reader = System.IO.File.OpenRead(filePath);
//文件传送的剩余字节数:初始值为文件的总大小
long Length = Reader.Length;
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="System.Web.HttpUtility.UrlEncode(fileName));
HttpContext.Current.Response.AddHeader("Content-Length", Length.ToString());
byte[] Buffer = new Byte[10000];//存放欲发送数据的缓冲区
int ByteToRead; //每次实际读取的字节数
while (Length0)
{
//剩余字节数不为零,继续传送
if (HttpContext.Current.Response.IsClientConnected)
{
//客户端浏览器还打开着,继续传送
ByteToRead = Reader.Read(Buffer, 0, 10000);//往缓冲区读入数据
HttpContext.Current.Response.OutputStream.Write(Buffer, 0, ByteToRead);
//把缓冲区的数据写入客户端浏览器
HttpContext.Current.Response.Flush(); //立即写入客户端
Length -= ByteToRead;//剩余字节数减少}
else
{
//客户端浏览器已经断开 , 阻止继续循环
Length = -1;
}
}//关闭该文件
Reader.Close();
}
QQ:121一九五五121
vb.net 如何指定访问来路来访问一个URL?'GET数据通用模板,返回源码
Function DownBitmap(ByVal URL_Post As String, ByVal Referer_Post As String, ByVal Accept_Post As String, ByVal UserAgent_Post As String _
, ByVal KeepAlive_Post As Boolean, ByVal CookieContainer_Post As CookieContainer) As Bitmap
Dim HttpPostUrl As New System.Uri(URL_Post)
Dim reqp As HttpWebRequest
reqp = CType(WebRequest.Create(HttpPostUrl), HttpWebRequest)
reqp.Method = "GET"
reqp.Referer = Referer_Post
reqp.Accept = Accept_Post
reqp.UserAgent = UserAgent_Post
reqp.KeepAlive = KeepAlive_Post
reqp.CookieContainer = CookieContainer_Post '设置Cookie
Dim resP As WebResponse = reqp.GetResponse
Dim bmp As Bitmap = New Bitmap(resP.GetResponseStream)
resP.Close() '关闭
Return bmp
End Function
用VB提取网页中的链接地址获得网页中vb.net获取url的超链接网址对一些网络编程很有用处,很多朋友都不会用,今天vb.net获取url我就交给大家怎么才能在VB6.0中实现这个功能,首先新建一个工程,加入webbrowser和scriptlet控件(引用部件Microsoft HTMl object Library添加一个Listbox控件(用于存放读出vb.net获取url的网址)命名为(listurl),个textbox()控件用于打开网址命名为txtsearchOption ExplicitDim UrlNow As IHTMLDocument2Private Sub CmdGeturl_Click() 'WebBrowser1.Stop 'Dim UrlNow On Error GoTo errordes Set UrlNow = WebBrowser1.Document If UrlNow Is Nothing Then MsgBox "当前页面没有链接", vbInformation, "注意" Else Dim UrlIndex As Long For UrlIndex = 0 To UrlNow.links.length - 1 ListUrl.AddItem UrlNow.links(UrlIndex) Next UrlIndex End If Exit Suberrordes: MsgBox "未知错误", vbCritical, "错误" End SubPrivate Sub Cmdstart_Click() WebBrowser1.Navigate2 txtSearch.Text End Sub这个就完具体请看vb.net获取url我vb.net获取url的博客:
vb.net获取url的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbs获取当前路径、vb.net获取url的信息别忘了在本站进行查找喔 。
推荐阅读
- 电脑怎么下载到u盘歌,电脑如何下载到u盘歌曲
- 下载火萤,下载火萤视频壁纸
- ERP系统在企业中应用的案例,erp系统在企业管理中的应用
- 小象Python爬虫,小象采集软件教程
- linux清除断点命令 linux如何中断命令
- 鸿蒙系统安装之后数据还在,安装鸿蒙系统会删除文件吗
- flutter数据刷新重绘,flutter 刷新listview
- 直播产品运营薪资,直播产品运营薪资高吗
- linux读寄存器命令 linux读写寄存器