如何使用c#从网络博客中阅读博客文章? [英] How to read blog post from a web blog using c# ?
问题描述
你好
我的基于C#的网站包含两个文本框.txtURL和txtRead以及一个按钮btnRead.
我希望我放置一个网络博客的帖子链接....例如,对于博客http://www.withpc.in/,现在对博客http://www.withpc.in/2011/08 /top-social-media-website-beyond.html
我想要的是,如果我将链接添加到txtURL并单击btnRead,则该帖子进入文本框txtRead(仅是帖子文本)
这就像去一个网站并在那里阅读帖子.我想使用C#进入我的文本框中的同一篇文章,以便我可以使用文本框在页面上阅读它.
我也尝试了这段代码,但它提供了页面的html编码,我想要的是帖子内容.
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.
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
推荐答案
最后尝试一下.
Try this at the end.
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
这将使您获得所有评论的帖子. main-wrapper
是保存这些内容的div.另一种方法是解析文件中的HTML内容.
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.
这篇关于如何使用c#从网络博客中阅读博客文章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!