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
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ScanForZIPs()
End Sub
Private Sub ScanForZIPs()
Dim Reader As New StreamReader("<path to the downloaded webpage>")
Dim HTMLSource As String = Reader.ReadToEnd()
Dim Pattern As String = "(?<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 As New Regex(Pattern, RegexOptions.IgnoreCase) 'Define the Regex.
Dim mc As MatchCollection = RgEx.Matches(HTMLSource) 'Check for matches in the HTML source.
Dim MatchList As New List(Of String) 'List of strings for the matched links.
For Each m As Match In mc 'Loop through each match.
MatchList.Add(m.Value) 'Add the value (link) of each match to the MatchList.
Next
Dim ZipsList As New List(Of String) 'List of links that ends with .zip.
For Each s As String In MatchList 'Loop through each string in MatchList.
If s.ToLower.ToString.EndsWith(".zip") = True Then 'Check if the link ends with .zip.
ZipsList.Add(s) 'Add the link to the list.
End If
Next
MessageBox.Show(ZipsList.Count & " .zip files found", "", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Display how many .zip files were found on the page.
Dim SelectZip As New SelectDownload 'Define a new download form.
For Each z As String In 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.
End Sub
End Class
The SelectDownload form. :)
Post a Comment for "Can I Download A File From A Website With A Download Link? Visual Basic"