Covert web page to array and sort net Visual basic

chadmanvb
chadmanvb used Ask the Experts™
on
I some code that opens IE to a web page.  Instead of doing that I would like to read the text on the web page, parse out some stuff, sort it, and display it in a text box.  Below is what the web page looks like:

SOFTSERV.ZSERVICE.WSAVCLIENT ver 0101_COR_00
SOFTSERV.ZSERVICE.WAPECSCLIENTTS ver 0408_COR_00 removal D
SOFTSERV.ZSERVICE.WKB948496 ver 0100_COR_00
SOFTSERV.ZSERVICE.WDOTNETFRAMEWRK ver 0200_COR_00 removal D
AUDIT.ZSERVICE._HARDWARE_SOFTWARE_AUDIT
SOFTSERV.ZSERVICE.WKB931836 ver 0001_COR_00
SOFTSERV.ZSERVICE.DAILY_TERMINAL_SERVER_TIMERS
SOFTWARE.ZSERVICE.RADIA40

I would like it to look like this:
WAPECSCLIENTTS      0408_COR_00
WDOTNETFRAMEWRK      0200_COR_00
WKB931836      0001_COR_00
WSAVCLIENT      0101_COR_00



I need it to skip lines that don’t contain "ver", remove the " SOFTSERV.ZSERVICE." from the first text, and only show the text/number after "ver".  I was trying to read the web page into a variable, but did not have any luck yet doing it.   If you have an example, could you show it in visual basic?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can read all this content into dataset.
Then select only those rows which contains 'ver'
Remove "SOFTSERV.ZSERVICE" from whole single line and read upto 'ver'
add all these rows in array/arraylist.
Sort them and display.

more info:
http://www.codeproject.com/KB/database/DataSetFrmDelimTxt.aspx

Author

Commented:
I could try that, but I was not sure how to read the web page.

Author

Commented:
Here is what I am trying to use now to get the web page into a string:
webstring=http://mywebpage


 Dim page As String = GetPage(WebString)
        MsgBox(page)
   Function GetPage(ByVal pageUrl As String) As String
      Dim s As String = ""
      Try
         Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
         Dim response As HttpWebResponse = request.GetResponse()
         Using reader As StreamReader = New StreamReader(response.GetResponseStream())
            s = reader.ReadToEnd()
         End Using
      Catch ex As Exception
         Debug.WriteLine("FAIL: " + ex.Message)
      End Try
      Return s
   End Function

Currently this brings back a blank messagebox.  If I put the url in my browser it works fine.
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Commented:
you code works fine for me grabbing http://www.google.com

I modified it a little, so it should work out fine - can you send me the (rendered) html-page?


Function GetPage(ByVal pageUrl As String) As String()
        Dim retList As New List(Of String)

        Try
            Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
            Dim response As HttpWebResponse = request.GetResponse()
            Using reader As StreamReader = New StreamReader(response.GetResponseStream())
                While Not reader.EndOfStream
                    Dim currentString As String = reader.ReadLine()
                    If (currentString.Contains(" ver ")) Then
                        Dim rowWords() As String = currentString.Split(" ")
                        If (rowWords.Length > 0) Then
                            Dim i As Integer
                            For i = 0 To rowWords.Length - 1
                                If (rowWords(i) = "ver" AndAlso i > 0 AndAlso i < rowWords.Length) Then
                                    retList.Add(String.Concat( _
                                                rowWords(i - 1).Replace("SOFTSERV.ZSERVICE.", ""), _
                                                " ", _
                                                rowWords(i + 1) _
                                                ))
                                End If
                            Next
                        End If
                    End If
                End While
            End Using
        Catch ex As Exception
            Debug.WriteLine("FAIL: " + ex.Message)
        End Try

        Return retList.ToArray()
    End Function


'---------------------------

        Dim verFound() As String = GetPage("http://localhost")
        If (verFound.Length > 0) Then
            'first hit
            MsgBox(verFound(0))
        End If

Open in new window

Author

Commented:
I am still not getting anything from the web page with that function when I use:
    Dim strPrefix As String = "http://nwpsrv11:3467/policy/uom?dn="  'prefix for the url
        Dim strEnd As String = "&inside=0"              'end of the url
        Dim locations As String = strWebString                              'ad location

        Dim WebString As String = strPrefix & System.Web.HttpUtility.UrlEncode(locations) & strEnd  'this will add prefix, ad location, and end of url







        Dim testme() As String = (GetPage(WebString))
        Dim testme1 As String = "'"
        Dim testme2 As String = ""


       
        For Each line As String In testme

            testme1 = line
            testme2 = testme2 & vbCrLf
            'Console.WriteLine(fruit)

        Next line
        MsgBox(testme2)     ' **********************get a blank msgbox

Process.Start("IExplore.exe", WebString)    '**************************this opens IE to the correct webpage and displays the text



Any ideas what I am missing

Author

Commented:
Great!!!!  That did it.  I just had to add one line after the first DIM.   request.Accept = "text/html"

Now I can just sort the array and everyones happy!  Thanks again.

Commented:
if you copy a blank string to a blank string (  testme2 = testme2 & vbCrLf) what do you expect?
maybe you should do something like that:
 testme2 = testme1 & vbCrLf
and try it again

Author

Commented:
Sorry, that was just a typo I forgot to change before I cut/pasted to here.  I had a blank string before.  Once I added the line below it worked.  You were correct that it worked fine with other web pages.  For some reason I had to add this line for the page I needed.

Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
request.Accept = "text/html"  '***********this fixed it

Commented:
So if i get it right, it works right now with the line you added :-). That is good to hear. Good you figured it out. I will keep that in mind if I stumble about that effect myself ;-).
Didn't mean to be rude - if I read my last comment right now I kinda blush a little *g*,

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial