Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将使用HAP解析的网页表保存到与网页布局相同的文本文件中?_C#_Html_Asp.net_Html Agility Pack - Fatal编程技术网

C# 如何将使用HAP解析的网页表保存到与网页布局相同的文本文件中?

C# 如何将使用HAP解析的网页表保存到与网页布局相同的文本文件中?,c#,html,asp.net,html-agility-pack,C#,Html,Asp.net,Html Agility Pack,我一直在使用HAP解析我的表,它正以我希望的方式完美地显示在使用此代码的网页中 foreach(var table in doc.DocumentNode.SelectNodes("//table")) { //Response.Write("Found: " + table.Id); foreach(HtmlNode row in table.SelectNodes("tr")) { Response.Write("<br>");

我一直在使用HAP解析我的表,它正以我希望的方式完美地显示在使用此代码的网页中

foreach(var table in doc.DocumentNode.SelectNodes("//table"))
{
    //Response.Write("Found: " + table.Id);
    foreach(HtmlNode row in table.SelectNodes("tr"))
    {
        Response.Write("<br>");
        foreach(HtmlNode cell in row.SelectNodes("th|td"))
        {
            Response.Write(cell.InnerHtml + "<br>");
        }
    }
}
foreach(doc.DocumentNode.SelectNodes(“//表”)中的变量表)
{
//响应。写入(“找到:+table.Id”);
foreach(表中的HtmlNode行。SelectNodes(“tr”))
{
响应。写入(“
”); foreach(第行中的HtmlNode单元格。选择节点(“th | td”)) { Write(cell.InnerHtml+“
”); } } }
它是这样打印出来的

阿里,萨利赫(#82358)
邮政信箱:0001
阿布扎比0000
阿拉伯联合酋长国
电话:+1234567890

阿里,萨利赫(#82358)
邮政信箱:0001
阿布扎比0000
阿拉伯联合酋长国
电话:+1234567890

等等

我正试图让它像那样写入一个文件,当我将它添加到foreach语句中写入单元格时,遇到了一个问题

sb1.Append(cell.InnerHtml + "<br>");
sb1.AppendLine();
sb1.Append("<br>");
sb1.Append(cell.InnerHtml+“
”); sb1.AppendLine(); sb1.追加(“
”);
这是在完成循环之后

string str3 = str2.Replace("<br>", Environment.NewLine).Replace("&nbsp;", " ")
            .Replace("                        ", "");
System.IO.File.WriteAllText(@"C:\BBBBB.txt", str3);
string str3=str2.Replace(
),Environment.NewLine.Replace(“,”) .替换(“,”); System.IO.File.writealText(@“C:\BBBBB.txt”,str3);
当我查看文本文件时,它的外观几乎与网页中的一样,但我必须处理大量的空白。但是,如果我从浏览器中将html页面保存为文本文件(运行应用程序时),它将以文本文件的形式显示它在网页上的外观

我尝试过,将单元格的innerHtml写入文本文件,并尝试过保存单元格的内部文本,但无论如何,我仍然发现自己必须替换字符串


当保存到文本文件时,如何使网页布局保持一致?

如果使用.html扩展名而不是.txt来保存文件,会怎么样?我有,而且它在网页中看起来是一样的,这正是我想要的方式,但我需要它保存为文本文件,因为我会在以后添加到它,一旦你不把它从.txt加载到一个内存流中,并在你添加完?@CalvinSmith后将它写为html,页面本身就保存为html文件,但当我将它保存到文本文件时,我仍然希望它保持它在html上的外观page@Chris我不确定您希望.txt文件如何同时成为.txt文件和.html文件。。。?