Cor3Quad Posted January 13, 2014 Report Posted January 13, 2014 Vreau sa preiau niste date de pe un site (de forma <span id="epm_asd_1" class="bold">50</span>) si sa le afieseze in program..ii ceva de genu (mentionez ca nu ma pricep prea bine) :label1 - preluat de pe un sitelabel2 = 0 => creste dupa ce porneste progressbar pana la "label1"label3 - preluat de pe siteprogressbar = trebuie sa mearga proportional si sa "dureze" random , in functie de label1(daca label1 = 100 ->1 minut).exemplu :Label1 = 50label2 = 0 (tot timpu)label3 = 20Care ii problema :Porneste progressbar-ul si "dureaza" 0,30 secunde ; - label 2 trebe sa creasca pana la label 1(50) ; Cum fac toate astea ? Progressbar-ul sa "dureze" o anumita durata de timp in functie de label 1 , label 2 sa creasca pana la label 1 si cum preiau datele de pe un site ? Quote
tudor13mn13 Posted January 14, 2014 Report Posted January 14, 2014 Imports System.Text.RegularExpressionsButton1 -> Care ia datele: Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("[b][url]http://site.com/[/url][/b]") Dim response As System.Net.HttpWebResponse = request.GetResponse Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream()) Dim rssourcecode As String = sr.ReadToEnd Dim r As New System.Text.RegularExpressions.Regex("[b]<span id=""epm_asd_1"" class=""bold"">50</span>[/b]")'[b] O Sa extraga ce este intre > si </[/b] Dim matches As MatchCollection = r.Matches(rssourcecode) For Each itemcode As Match In matches label1.text = (itemcode.Value.Split("></").GetValue(1)) 'System.Threading.Thread.Sleep(600) Timer1.Start() 'TextBox1.RegexObj.Replace("subject", "replacement") NextTimer1--Progressbar1.Value = progressbar1.value + 3If Progressbar1.value = 99 Thentimer1.stop()progressbar1.value = 100timer1.stop() 'in caz ca nu se opreste cand trebuieEnd If[Mai Departe sper ca te descurci tu] !!RegularExpression => adica codul html din care vrei sa extragi :De exemplu : <span id="epm_asd_1" class="bold">50</span>Sper ca ti-a fost de ajutor ! Quote
Cor3Quad Posted January 14, 2014 Author Report Posted January 14, 2014 (edited) Imports System.Text.RegularExpressionsPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Start() Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.1234.com/pages/") Dim response As System.Net.HttpWebResponse = request.GetResponse Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream()) Dim rssourcecode As String = sr.ReadToEnd Dim r As New System.Text.RegularExpressions.Regex("<span id=""epm_ads_1"" class=""bold"">50</span>") ' O Sa extraga ce este intre > si </ Dim matches As MatchCollection = r.Matches(rssourcecode) For Each itemcode As Match In matches Label5.Text = (itemcode.Value.Split("></").GetValue(1)) 'System.Threading.Thread.Sleep(600) 'TextBox1.RegexObj.Replace("subject", "replacement") Next End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ProgressBar1.Value = ProgressBar1.Value + 3 ProgressBar1.Increment(1) Label6.Text = ProgressBar1.Value & (" % ") If ProgressBar1.Value = 100 Then Label6.Text = "Done" Timer1.Stop() End If End SubEnd ClassTimer-ul l-am mai adaptat eu , problema ii ca nu primesc nimic de pe site + ca se blocheaza cateva secunde cand dau sa preia datele. Edited January 14, 2014 by Cor3Quad Quote
Byte-ul Posted January 14, 2014 Report Posted January 14, 2014 cum sa primesti ceva de pe site daca nu e nimic de primit?http://www.1234.com/pages/Nu inteleg de ce ai pus incrementu. practic faci value=value +4 Quote
Cor3Quad Posted January 14, 2014 Author Report Posted January 14, 2014 cum sa primesti ceva de pe site daca nu e nimic de primit?http://www.1234.com/pages/Nu inteleg de ce ai pus incrementu. practic faci value=value +4Nu mai stiu de ce l-am pus Iar in VB , la adresa era pus bine , aici am editat cand am postat.Cum adica vrei sa iei date de forma <span id="epm_asd_1" class="bold">50</span> ?Adica vrei sa iei ce este intre taguri? (<span id="epm_asd_1" class="bold">50</span>)Banuiesc (,) ca 50 se schimba in alte cife (10,30 etc.)Daca da uite aici:Edit:Tre' sa importi Imports System.Net .Imports System.NetPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim wc As New WebClient Dim html As String html = wc.DownloadString("http://www.1234.com/pages/") Label1.Text = GetBetween(html, "<span id=""epm_asd_1"" class=""bold"">", "</span>") End Sub Private Function GetBetween(ByVal sSearch As String, ByVal sStart As String, ByVal sStop As String, Optional ByVal lSearch As Integer = 1) As String Dim lTemp As Long lSearch = InStr(lSearch, sSearch, sStart) If lSearch > 0 Then lSearch = lSearch + Len(sStart) lTemp = InStr(lSearch, sSearch, sStop) If lTemp > lSearch Then Return Trim(Mid$(sSearch, lSearch, lTemp - lSearch)) End If Return vbNullString End FunctionEnd ClassProblema : A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dllNu apare nimic la Label. Quote
Cor3Quad Posted January 14, 2014 Author Report Posted January 14, 2014 A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dllNu apare nimic in labelImports System.NetPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim wc As New WebClient Dim html As String html = wc.DownloadString("http://www.1234.com/pages/") Label1.Text = GetBetween(html, "<span id=""epm_ads_1"" class=""bold"">", "</span>") End Sub Private Function GetBetween(ByVal sSearch As String, ByVal sStart As String, ByVal sStop As String, Optional ByVal lSearch As Integer = 1) As String Dim lTemp As Long lSearch = InStr(lSearch, sSearch, sStart) If lSearch > 0 Then lSearch = lSearch + Len(sStart) lTemp = InStr(lSearch, sSearch, sStop) If lTemp > lSearch Then Return Trim(Mid$(sSearch, lSearch, lTemp - lSearch)) End If Return vbNullString End FunctionEnd Class Quote
Cor3Quad Posted January 14, 2014 Author Report Posted January 14, 2014 Nu am mai editat nimic decat site-ul , same story , doar ca :A first chance exception of type 'System.Net.WebException' occurred in System.dll Quote
Byte-ul Posted January 14, 2014 Report Posted January 14, 2014 Nu am mai editat nimic decat site-ul , same story , doar ca :A first chance exception of type 'System.Net.WebException' occurred in System.dllpune try, catch si uita-te unde ai eroarea. Quote
Cor3Quad Posted January 15, 2014 Author Report Posted January 15, 2014 Unde mai exact sa pun ? Nu prea ma pricep.. Quote