VB.NET - 从网页下载文件 [英] VB.NET - Downloading File From Webpage

查看:70
本文介绍了VB.NET - 从网页下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 http://Kodi.tv/download 下载适用于 Android 的最新 Kodi ARM 版本,并将其保存到我计算机上的一个预先存在的文件夹中.我只想单击一个按钮,它就会将该文件下载到需要的位置.我当前使用的代码是打开 IE 浏览器并进行对话;

I am trying to download the latest Kodi ARM build for Android from http://Kodi.tv/download and save it to a pre-existing folder on my computer. I just want to click a button and it will download that file to where it needs to be. The current code that I am using is opening up an IE browser and giving the dialogue;

打开、保存、另存为..

Open, Save, Save As..

这是我当前使用的代码:

Here is the current code that I am using:

For Each Element As HtmlElement In WebBrowser1.document.GetElementsByTagName("a")
        If Element.OuterHtml.Contains("ARM") Then
            Element.InvokeMember("click")
           End If
    Next

这是从表单上的 Webbrowser 中抓取按钮并单击它.我也不能使用静态链接,因为我想获得最新的更新 [链接更改].

This is grabbing the button off of the Webbrowser that I have on the form and clicking it. I also can not use a static link as I want to get the latest updates [link changes].

如何在没有对话的情况下将我需要的项目从网页下载到预先指定的文件夹?

How can I download the item I need from the web page to a predesignated folder with no dialogues?

推荐答案

我在网上找到了这段代码,效果很好,所以我想我会分享它!

I found this code online and it works great so i thought i would share it!

 Dim Address As String = String.Empty
    Dim filename As String = String.Empty
    Try
        Dim fileReader As New WebClient()
        Address = " *Link* "
        filename = " *Filename of what you want to save as* "
        If Not (System.IO.File.Exists(" *Download Location* " + filename)) Then
            fileReader.DownloadFile(Address, " *Download Location* " + filename)
        End If
    Catch ex As HttpListenerException
        Console.WriteLine("Error accessing " + Address + " - " + ex.Message)
    Catch ex As Exception
        Console.WriteLine("Error accessing " + Address + " - " + ex.Message)
    End Try
    MsgBox("Done")
End Sub

在这里找到:这里

这篇关于VB.NET - 从网页下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆