|
-
Feb 26th, 2011, 04:48 PM
#1
Thread Starter
Junior Member
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
-
Feb 26th, 2011, 04:55 PM
#2
Thread Starter
Junior Member
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
-
Feb 26th, 2011, 05:49 PM
#3
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
-
Feb 27th, 2011, 11:37 AM
#4
Thread Starter
Junior Member
Re: Getting a section of a site into a label
 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
-
Mar 1st, 2011, 09:10 PM
#5
Thread Starter
Junior Member
Re: Getting a section of a site into a label
-------------BUMP---------------------------------------------------BUMP----
Any help
-
Mar 2nd, 2011, 04:30 AM
#6
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...
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|