Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

My website based on C# contains two text boxes.. txtURL and txtRead and a button btnRead.

I want that if i put a web blog's post link.... i.e. for the blog http://www.withpc.in/ and now for the post http://www.withpc.in/2011/08/top-social-media-website-beyond.html

I want that if i add the link to the txtURL and Click on btnRead then the Post comes to textbox txtRead (only the post text )

It is like going to a website and reading a post there. The same post i want to get on my text box using C# so that i can read it on my page using textbox.


Also i tried this code but it gives the html coding of the page and i want is the post content.

C#
using System; 
using System.IO; 
using System.Net; 
using System.Text; 


    public static void GetFile 
            ( 
            string strURL, 
            string strFilePath 
            ) 
        { 

            WebRequest myWebRequest = WebRequest.Create(strURL);  

            WebResponse myWebResponse = myWebRequest.GetResponse();  

            Stream ReceiveStream = myWebResponse.GetResponseStream(); 
                
            Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); 

            StreamReader readStream = new StreamReader( ReceiveStream, encode ); 

            string strResponse=readStream.ReadToEnd(); 
                 
            StreamWriter oSw=new StreamWriter(strFilePath); 
     
            oSw.WriteLine(strResponse); 

            oSw.Close(); 

            readStream.Close(); 
         
            myWebResponse.Close(); 

        } 


So please suggest me the methods to read the blog content.

Thanks
Posted

1 solution

Try this at the end.
VB
Dim wb As New WebBrowser
Dim doc As HtmlDocument
wb.Document.Write(IO.File.ReadAllText(strFilePath))
'You can get result by
'wb.Document.GetElementById("main-wrapper").InnerText

This will get you the post with all comments. main-wrapper is the div which holds these content. The other way is to parse the HTML content in the file.
 
Share this answer
 
v2
Comments
LockedOut 26-Aug-11 9:55am    
Hey can you please elobrate bit more about this "main-wrapper" code with some example.

Thanks

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