Hi,
I need to read and parse a webpage to obtain certain information from it on a daily basis, in a VB.NET environment. I can successfully initialise the request and can receive some information from the webpage in question, but its as if it sometimes times out and only returns to me what I managed to obtain from the stream while it was alive. Sometimes I manage to get only around 500 of the lines into my arraylist at the end. Please see my code and see if Im missing something...
I need to read and parse a webpage to obtain certain information from it on a daily basis, in a VB.NET environment. I can successfully initialise the request and can receive some information from the webpage in question, but its as if it sometimes times out and only returns to me what I managed to obtain from the stream while it was alive. Sometimes I manage to get only around 500 of the lines into my arraylist at the end. Please see my code and see if Im missing something...
Code:
Dim arrBuff As New ArrayList() Results go in here
Dim myHttpWebRequest As HttpWebRequest
Dim myHttpWebResponse As HttpWebResponse
Dim receiveStream As Stream
Dim encode As Encoding
Dim sr As IO.StreamReader
Try
myHttpWebRequest = CType(WebRequest.Create(strURL), HttpWebRequest)
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
receiveStream = myHttpWebResponse.GetResponseStream()
encode = System.Text.Encoding.GetEncoding("utf-8")
sr = New StreamReader(receiveStream, encode)
Do Until sr.Peek = -1
strLine = sr.ReadLine
arrBuff.Add(strLine)
Loop
Catch ex As System.Net.WebException
MsgBox(ex.Message)
Finally
sr.Close()
myHttpWebResponse.Close()
End Try