I have VB code with HttpWebRequest that collects html of hundreds of websites but takes very long time to complete the task. Code basically is a for-to-loop and reads html of the each website in the listbox. In a loop, the extracted html of each website is searched for specific words. I want to display list of website that has word under each word column.
For Each webAddr As String In lstbox.Items
strHtml = Make_A_Call(webAddr)
If strHtml.Contains("Keyword1") Then
..........
End If
If strHtml.Contains("Keyword2") Then
..........
End If
..........
..........
..........
..........
..........
Next
Private Function Make_A_Call(ByVal strURL As String) As String
Dim strResult As String
Dim wbrq As HttpWebRequest
Dim wbrs As HttpWebResponse
Dim sr As StreamReader
Try
strResult = ""
wbrq = WebRequest.Create(strURL)
wbrq.Method = "GET"
' Read the returned data
wbrs = wbrq.GetResponse
sr = New StreamReader(wbrs.GetResponseStream)
strResult = sr.ReadToEnd.Trim
sr.Close()
sr.Dispose()
wbrs.Close()
Catch ex As Exception
ErrMessage.Text = ex.Message.ToString
ErrMessage.ForeColor = Color.Red
End Try
Return strResult
End Function
Compiled code takes almost 5 minutes to complete the loop. Some times it fails to complete. Can it be modified to impove the performance. Please, help with better code and suggestions.