Click here to Skip to main content
15,903,784 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello... I have a bit of code that displays the HTML of a webpage.

VB
Public Sub Lookup()
       Dim WebAddress As String = "http://www.yahoo.com"
       ' Create a request for the URL.
       Dim request As WebRequest = _
         WebRequest.Create(WebAddress)
       ' If required by the server, set the credentials.
       request.Credentials = CredentialCache.DefaultCredentials
       ' Get the response.
       Dim response As WebResponse = request.GetResponse()
       ' Display the status.
       Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
       ' Get the stream containing content returned by the server.
       Dim dataStream As Stream = response.GetResponseStream()
       ' Open the stream using a StreamReader for easy access.
       Dim reader As New StreamReader(dataStream)
       ' Read the content.
       Dim responseFromServer As String = reader.ReadToEnd()
       ' Display the content.
       Label2.Text = WebAddress
       Label3.Text = responseFromServer
       ' Clean up the streams and the response.
       reader.Close()
       response.Close()
   End Sub



My problem is not with this code but thought id share it...
My question is how can i take specific strings from the HTML output to my label and display a specific value or string from the output to a label or textbox.

the code above i know lists all of the html code for a given page but I need to single out specific values or strings.

thank you in advance!
Posted

1 solution

Well, if it's XHTML, you can try putting it into an Xml.XmlDocument, and parsing the nodes. Otherwise you're going to manually parse the document
 
Share this answer
 
Comments
Dale 2012 5-Sep-12 16:16pm    
this will probably work but can you give a bit more insight into how to parse html and the nodes that you are talking of.

thank you
MarqW 6-Sep-12 2:38am    
Well, I already suggested you try loading it into an Xml.XmlDocument, you can then use the .SelectNodes, .SelectSingleNodes, and .Children to navigate around.

Failing that, use functions such as InStr, Mid, and Split to find key identifying phrases and manually compute the data

Alternatively:
http://www.google.co.uk/search?q=parsing+html+vb.net&oq=parsing+html+vb.net
Dale 2012 6-Sep-12 19:14pm    
thank you very much!!
Dale 2012 6-Sep-12 20:16pm    
I have read about these methods but I still need some example of how to read the html from my rich textbox to find the strings I am looking for. It is not always known to me what the numbers are so a predefined value to search for like 25 or 32 will not work I need to search or parse strings that are like " 1 out of 0" and so on. also functions such as instr, mid and split are old and may cause a performance hit to the program.

I have google searched for hours but cannot figure this out please provide some example

thank you for your input!
MarqW 10-Sep-12 3:21am    
You don't search for the content you are after. look at the HTML *around* your values.
If your data is in a textbox, and the html looks like "<input id='indicator' style='text' value='some value'>", search for "<input id='indicator'", then crawl through looking for "value=" then parse the value from the quotes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900