Results 1 to 6 of 6

Thread: Getting a section of a site into a label

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    23

    Getting a section of a site into a label

    Hey guys,

    I have been trying for days now to get just one part of a webpage into a label <div class="c411ListingEntry">

    </div>

    basically i want to get everything listed in that div call into a label (the div class is all text anyways)

    Thanks in advance

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    23

    Re: Getting a section of a site into a label

    here is the code im using so far but i just want to get the <div class='c411ListingEntry'>
    vb Code:
    1. Public Function DownloadHTMLPage(ByVal _URL As String) As String
    2.         Dim _PageContent As String = Nothing
    3.         Try
    4.             ' Open a connection
    5.             Dim _HttpWebRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(_URL), System.Net.HttpWebRequest)
    6.  
    7.            
    8.             ' set timeout for 10 seconds (Optional)
    9.             _HttpWebRequest.Timeout = 10000
    10.  
    11.             ' Request response:
    12.             Dim _WebResponse As System.Net.WebResponse = _HttpWebRequest.GetResponse()
    13.  
    14.             ' Open data stream:
    15.             Dim _WebStream As System.IO.Stream = _WebResponse.GetResponseStream()
    16.  
    17.             ' Create reader object:
    18.             Dim _StreamReader As New System.IO.StreamReader(_WebStream)
    19.  
    20.             ' Read the entire stream content:
    21.             _PageContent = _StreamReader.ReadToEnd()
    22.  
    23.             ' Cleanup
    24.             _StreamReader.Close()
    25.             _WebStream.Close()
    26.             _WebResponse.Close()
    27.         Catch _Exception As Exception
    28.             ' Error
    29.             Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())
    30.             Return Nothing
    31.         End Try
    32.  
    33.         Return _PageContent
    34.     End Function

  3. #3
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Getting a section of a site into a label

    And you're stuck where?
    Just need to find the text "<div class="c411ListingEntry">", and get all the text until the </div>, if you don't have other div's inside...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    23

    Re: Getting a section of a site into a label

    Quote Originally Posted by mickey_pt View Post
    And you're stuck where?
    Just need to find the text "<div class="c411ListingEntry">", and get all the text until the </div>, if you don't have other div's inside...
    yea i know but im having trouble coding that to make it just get the starting of the c411ListingEntry then end at <div> and i also want it to remove all <a> <br> <div> after

    Code:
                ' Read the entire stream content:
           _PageContent = _StreamReader.string

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    23

    Re: Getting a section of a site into a label

    -------------BUMP---------------------------------------------------BUMP----

    Any help

  6. #6
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Getting a section of a site into a label

    You could use RegEx to do that, other way it's just use string find and replace you need a lot more code than the RegEx version...

    A simple example to get the content of the div, assuming that you don't have any div's inside this one:
    vb.net Code:
    1. Dim divToFind As String = "<div class=""c411ListingEntry"">"
    2. Dim divContent As String = _PageContent.Substring(_PageContent.IndexOf(divToFind) + divToFind.Length, _PageContent.IndexOf("</div>") - _PageContent.IndexOf(divToFind) + divToFind.Length) 'I'm assuming that there isn't any DIV inside this DIV
    3. divContent.Replace("<br />", String.Empty) 'Replace NewLines with nothing
    The only problem it's that for each <a> tag you need to get the size of it, to know exactly what you have to remove...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width