Hey everbody, i got 2 problems while programming my new project.
I hope you can maybe help me.
i want to read some strings like a price from different webpages.
so i need to define some RegEx.
Currently i am doing it this way, but in some cases, its not working and i get dirty output like € 10.00 and i cant get it to work by html src like
Code:<h1> <nobr> €29.90 </nobr> </h1>The other problem is, i want to use GetMe in some Backgroundworker so the application wont freeze while grabbing the price.Code:Public Function GetMe(ByVal URLX As String, ByVal REGSTART As String, ByVal REGEND As String) As String Dim Client As New WebClient() Dim Html As String = Client.DownloadString(New Uri(URLX)) Dim regex As Regex = New Regex("(" & REGSTART & "(.*)" & REGEND & ")", RegexOptions.IgnoreCase) Dim match As MatchCollection = regex.Matches(Html) Dim sb As StringBuilder = New StringBuilder For Each items As Match In match sb.Append(items.ToString & vbLf) Next Dim s As String = regex.Replace(sb.ToString, "<[^>,]*?>", String.Empty, RegexOptions.Singleline) s = regex.Replace(s, "\\n", String.Empty, RegexOptions.IgnorePatternWhitespace).Trim Return s End Function
I am wondering why this is NOT working, because like i think should work.Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click BackgroundWorker1.RunWorkerAsync() End Sub Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork Dim sqlQuery As String = "SELECT * FROM tbl_data" Dim sqlAdapater As New MySqlDataAdapter Dim sqlCommand As New MySqlCommand Dim TABLE As New DataTable Dim i As Integer With sqlCommand .CommandText = sqlQuery .Connection = sConnection End With With sqlAdapater .SelectCommand = sqlCommand .Fill(TABLE) End With ListView1.Items.Clear() For i = 0 To TABLE.Rows.Count - 1 BackgroundWorker1.ReportProgress(i) With ListView1 .Items.Add(TABLE.Rows(i)("ID")) With .Items(.Items.Count - 1).SubItems .Add(TABLE.Rows(i)("Product")) .Add(TABLE.Rows(i)("Offer")) .Add(TABLE.Rows(i)("AURL")) .Add(TABLE.Rows(i)("BURL")) .Add(TABLE.Rows(i)("RegStart")) .Add(TABLE.Rows(i)("RegEnd")) .Add(GetMe((TABLE.Rows(i)("AURL")), (TABLE.Rows(i)("RegStart")), (TABLE.Rows(i)("RegEnd")))) .Add(GetMe((TABLE.Rows(i)("BURL")), "<h4>", "</h4>")) End With End With Next End Sub Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged ProgressBar1.Value = e.ProgressPercentage End Sub Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted MsgBox("Done!") End Sub
Thanks for help, i hope this community can help me![]()


LinkBack URL
About LinkBacks




Reply With Quote

Bookmarks