Hola, me preguntaba si se puede hacer un programa que descargue todos los recursos de una pagina "Juego Flash"
Tengo las "ID's" de los archivos algo asi por ejemplo
http://www.juego.com/juego/swf/id/001.swf
http://www.juego.com/juego/swf/id/002.swf
http://www.juego.com/juego/swf/id/003.swf
http://www.juego.com/juego/swf/id/004.swf
http://www.juego.com/juego/swf/id/005.swf
y se me toma muy molesto estar cambiando los "ID" de cada .swf
¿Existe alguna manera de hacerlo mas rapido? algo asi de poner todas las ID's en un "File.txt" y que el programa pase de Id, en Id y las descargue
No estoy delante de la IDE, si hay algun error de sintaxis corrígelo:
' dim strarray() as string = io.file.readalllines("C:\ids.txt")
for each ID as string in io.file.readalllines("C:\ids.txt"): downloader(ID) : next
private sub downloader(byval ID as string)
' descargar ID
dim url = nothing
try : url = new uri(ID) : catch : msgbox("Enlace no válido"): end try
...
end sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim client As WebClient = New WebClient
AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
client.DownloadFileAsync(New Uri("http://d1hmtg1vead5c8.cloudfront.net/sr/images/ships/swf_big_1.5.4/" & ListView1.SelectedItems(0).Text & ".swf"), (".\Archivos\") & ListView1.SelectedItems(0).Text & ".swf")
Button1.Text = "Please Wait"
Button1.Enabled = False
'If ListView1.SelectedItems.Count > 0 Then
' My.Computer.Network.DownloadFile("http://d1hmtg1vead5c8.cloudfront.net/sr/images/ships/swf_big_1.5.4/" & ListView1.SelectedItems(0).Text & ".swf", (".\Archivos\") & ListView1.SelectedItems(0).Text & ".swf")
'End If
End Sub
Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
Dim percentage As Double = bytesIn / totalBytes * 100
progressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
End Sub
Private Sub client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
Button1.Text = "Start Download"
Button1.Enabled = True
ProgressBar1.Value = 0
End Sub
Esto es algo de lo que llevo, como puedo integrar tu codigo con el mio.. es decir como puedo hacer que al presionar el "Button1" se descargue todo lo que hay en el "Listview1"
Sencillo:
For Each ID In ListBox1.Items
My.Computer.Network.DownloadFile(ID, ".\Archivos\" & ListView1.SelectedItems(0).Text & ".swf")
Next
No estoy seguro si va a funcionar, pero la idea seria algo así. ;)
Haces un ciclo en la colección de items del Listbox, y listo, como te ha comentado IkillNukes.
Saludos
Bieeeen, como me gusta no equivocarme cuando ayudo! :3
PD: Muy fuera del tema: Donde tás metio tol día Elektro?
PDS: Espero que se hayan arreglado tus dudas Syntax, ya sabes si tienes alguna duda más, pues posteala... ;)
Bien, gracias por sus ayudas pero les voy arruinar la fiesta >:D
(http://img197.imageshack.us/img197/3379/i7pi.png)
Descarga el code de fuente y usa regex para borrar lo que no quieras del archivo. :silbar:
Puedes parsear un documento JSON usando > JSON.NET (http://james.newtonking.com/projects/json-net.aspx) <
O puedes loopear todas las lineas del documento y filtrar usando > RegEx (http://en.wikipedia.org/wiki/Regular_expression) <
Dim json As String = <a><![CDATA["1010204": {]]></a>.Value
Dim [RegEx] As New System.Text.RegularExpressions.Regex(<a><![CDATA[\"(\d{7})\"]]></a>.Value)
MsgBox([RegEx].Match(json).Groups(1).ToString)
EDITO:
Dim JSON As String = IO.File.ReadAllText("File.json")
Dim Pattern As String = <a><![CDATA[\"(\d{7,7})\"]]></a>.Value
Dim Matches As Match = Regex.Match(JSON, Pattern)
Do While Matches.Success
MsgBox(Matches.Groups(1).ToString)
Matches = Matches.NextMatch()
Loop
Saludos.