Code:
Imports System.Net
Public Class Form1
Dim fileReader As String
Dim t As String()
Dim strami As String = ""
Dim s, r As String()
Dim orfWriter As System.IO.StreamWriter
Dim local As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
fileReader = My.Computer.FileSystem.ReadAllText("G:\test.txt")
RichTextBox1.Text = fileReader
Dim urls() As String = RichTextBox1.Lines
Parallel.ForEach(urls, Sub(f)
If Not String.IsNullOrEmpty(f) Then
t = f.Split(",")
name = t(0)
't(1)=web address of Name
DownloadAsync(t(1))
End If
End Sub)
My.Computer.Audio.PlaySystemSound(
System.Media.SystemSounds.Asterisk)
MsgBox("All Done!")
End Sub
Function DownloadAsync(URL As String) As Task(Of Boolean)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim html As String = ""
Dim result As Boolean
Dim request As HttpWebRequest = HttpWebRequest.Create(URL)
request.AutomaticDecompression = DecompressionMethods.GZip
request.Timeout = 500
request.Method = "GET"
request.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0"
Using response As Task(Of WebResponse) = request.GetResponseAsync
If response.Result IsNot Nothing Then
Using ioStream As IO.Stream = response.Result.GetResponseStream
Using sr As New System.IO.StreamReader(ioStream)
html = sr.ReadToEnd
s = html.Split(";")
r = s(0).Split(",")
'///////////////////
local = "G:" & Name.ToString + ".csv"
orfWriter = New System.IO.StreamWriter(local, True, System.Text.Encoding.Unicode)
strami = r(0) & "," & r(1) & "," & r(2) & "," & r(3)
orfWriter.Write(strami)
orfWriter.WriteLine("")
orfWriter.Close()
End Using
result = True
End Using
End If
End Using
Return Task.FromResult(result)
Return Task.FromResult(False)
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class