如何在c#中解析HTMLDocument?
我想使用 C# 中的简单应用程序获取 html 页面的文本? 如果有嵌套元素 即,
<Table>
<TR>
<TD>**ABC**
</TD>
<TD>**1**
</TD>
</TR>
<TR>
<TD>**XYZ**
</TD>
<TD>**2**
</TD>
</TR>
</Table>
如何直接获取文本(粗体)值。我想将它们保存在我的数据库中,并且还想在 gridview 中显示?
HtmlDocument htmlSnippet = new HtmlDocument();
htmlSnippet = LoadHtmlSnippetFromFile();
private HtmlDocument LoadHtmlSnippetFromFile()
{
//TextReader reader = File.OpenText(Server.MapPath("~/App_Data/HtmlSnippet.txt"));
WebClient webClient = new WebClient();
const string strUrl = "http://www.dsebd.org/latest_PE_all2_08.php";
Stream reader = webClient.OpenRead(strUrl);
HtmlDocument doc = new HtmlDocument();
doc.Load(reader);
reader.Close();
return doc;
}
从这个 htmlSnippet
我如何获取该值?
I want to get the text of an html page using a simple application in c#?
If there are nested elements
ie.,
<Table>
<TR>
<TD>**ABC**
</TD>
<TD>**1**
</TD>
</TR>
<TR>
<TD>**XYZ**
</TD>
<TD>**2**
</TD>
</TR>
</Table>
How can I get the text(bold) directly values.I want to save them in my database and also want to show in gridview?
HtmlDocument htmlSnippet = new HtmlDocument();
htmlSnippet = LoadHtmlSnippetFromFile();
private HtmlDocument LoadHtmlSnippetFromFile()
{
//TextReader reader = File.OpenText(Server.MapPath("~/App_Data/HtmlSnippet.txt"));
WebClient webClient = new WebClient();
const string strUrl = "http://www.dsebd.org/latest_PE_all2_08.php";
Stream reader = webClient.OpenRead(strUrl);
HtmlDocument doc = new HtmlDocument();
doc.Load(reader);
reader.Close();
return doc;
}
From this htmlSnippet
how could i get the value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您需要什么...根据您的示例,您想要一个字符串
"**ABC****1****XYZ****2**"
?那么这应该可以工作:
htmlSnippet.Body.OuterText
编辑:好的,尝试为单独的值提供一个示例...
抱歉,我现在没有 Visual Studio 来测试代码...祝你好运;-)
I'm not sure, what you need ... given your example, do you want a string
"**ABC****1****XYZ****2**"
?Then this should work:
htmlSnippet.Body.OuterText
EDIT: Ok, trying for a example for separate values ...
Sorry, I have no Visual Studio here right now to test the code ... good luck ;-)