Skip to content Skip to sidebar Skip to footer

Can I Download A File From A Website With A Download Link? Visual Basic

Is it possible to download a file from a website that offers a download button? I am trying to make a simple program that will download texture packs for Minecraft and install them

Solution 1:

Okay. So here's a possible solution for you.

Sadly it only works if the link is complete. (Starts with http:// etc...)

Imports System.Text.RegularExpressions
Imports System.IO

PublicClass Form1
    PrivateSub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        ScanForZIPs()
    EndSubPrivateSub ScanForZIPs()
        Dim Reader AsNew StreamReader("<path to the downloaded webpage>")
        Dim HTMLSource AsString = Reader.ReadToEnd()

        Dim Pattern AsString = "(?<Protocol>\w+):\/\/(?<Domain>[\w@][\w.:@]+)\/?[\w\.?=%&=\-@/$,]*"'Pattern, which the Regex will use in order to match links in the webpage.'Credits to IronRazerz (https://social.msdn.microsoft.com/profile/ironrazerz/?ws=usercard-mini) for giving me a fully working pattern.Dim RgEx AsNew Regex(Pattern, RegexOptions.IgnoreCase) 'Define the Regex.Dim mc As MatchCollection = RgEx.Matches(HTMLSource) 'Check for matches in the HTML source.Dim MatchList AsNew List(OfString) 'List of strings for the matched links.ForEach m As Match In mc 'Loop through each match.
            MatchList.Add(m.Value) 'Add the value (link) of each match to the MatchList.NextDim ZipsList AsNew List(OfString) 'List of links that ends with .zip.ForEach s AsStringIn MatchList 'Loop through each string in MatchList.If s.ToLower.ToString.EndsWith(".zip") = TrueThen'Check if the link ends with .zip.
                ZipsList.Add(s) 'Add the link to the list.EndIfNext

        MessageBox.Show(ZipsList.Count & " .zip files found", "", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Display how many .zip files were found on the page.Dim SelectZip AsNew SelectDownload 'Define a new download form.ForEach z AsStringIn ZipsList 'Loop through the found .zip links.
            SelectZip.ListBox1.Items.Add(z) 'Add them to the list in the SelectZip form.Next
        SelectZip.ListBox1.HorizontalScrollbar = True'Horizontall scrollbar in SelectZip's ListBox.
        SelectZip.ShowDialog() 'Display the SelectZip form.EndSubEndClass

The SelectDownload form. :)

The SelectDownloaf form.

Post a Comment for "Can I Download A File From A Website With A Download Link? Visual Basic"