解析在线书籍的页面,并保存页面及其页脚的内容,而不做任何更改
本文关键字:任何更 保存 在线 | 更新日期: 2023-09-27 17:59:47
<article class="js_IntraTCBP IntraTCBP dr tr lh2 js_lblContent" id="js_lblContent"><p></p>text
<p></p><p></p><a name="p1"></a><a name="p1"></a><a name="p1"></a><a name="p1"></a><a name="p1"></a><h1>text</h1><p></p><p></p>text
<p></p>text<sup>1</sup>
<p></p>text<sup>2</sup>
<p></p>text<sup>3</sup>
<p></p>text<sup>4</sup>text<p></p><hr class="Footer"><p></p><font class="Footer"><p></p>1-ddd
<p></p>2-ccc
<p></p>3-bbb
<p></p>4-aaa
</font></article>
文本
文本1
文本2
文本3
文本4文本
2-cc
3-bbb
4-aaa
我想解析在线书籍的页面,并保存页面内容而不做任何更改。
当我使用这个:
var pageContent=文档。DocumentNode.SelectNodes("//article[@class='js_IntraTCBP IntraTCBP dr tr lh2 js_lblContent']/text(("(;
它收到了我所有的短信。
我怎样才能得到所有的页脚。例如text1----->1=dddd。就像我在书上看到的一样。
您可以尝试正则表达式或Regex,它们是表示要搜索的字符串或模式的字符和符号序列。System.Text.RegularExpressions.Regex
类-MSDN。
可以使用Regex.Matches
来匹配一些html元素,但必须循环遍历每一行。这将让你开始:
// loop...
var matches = Regex.Match(line, @"('<['w]*'>|[^'s]*([^<]*)'<'/['w]*'>)");
要获得包含内容的标签,请使用:
string tag = matches.Groups[1].Value;
要获得不包括标签的内容,请使用:
string content = matches.Groups[2].Value;
演示。它可以检测某些元素,但不能检测所有元素。
以下是一些可能有助于学习的链接:
- https://msdn.microsoft.com/en-us/library/20bw873z.aspx
- https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110(.aspx
- http://www.dotnetperls.com/regex