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
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:
Public Function DownloadHTMLPage(ByVal _URL As String) As String
Dim _PageContent As String = Nothing
Try
' Open a connection
Dim _HttpWebRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(_URL), System.Net.HttpWebRequest)
' set timeout for 10 seconds (Optional)
_HttpWebRequest.Timeout = 10000
' Request response:
Dim _WebResponse As System.Net.WebResponse = _HttpWebRequest.GetResponse()
' Open data stream:
Dim _WebStream As System.IO.Stream = _WebResponse.GetResponseStream()
' Create reader object:
Dim _StreamReader As New System.IO.StreamReader(_WebStream)
' Read the entire stream content:
_PageContent = _StreamReader.ReadToEnd()
' Cleanup
_StreamReader.Close()
_WebStream.Close()
_WebResponse.Close()
Catch _Exception As Exception
' Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())
Return Nothing
End Try
Return _PageContent
End Function
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...
Re: Getting a section of a site into a label
Quote:
Originally Posted by
mickey_pt
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
Re: Getting a section of a site into a label
-------------BUMP---------------------------------------------------BUMP----
Any help
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:
Dim divToFind As String = "<div class=""c411ListingEntry"">"
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
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...