Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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# 如何将html转换为文档而不丢失段落?_C#_Html_Html Agility Pack - Fatal编程技术网

C# 如何将html转换为文档而不丢失段落?

C# 如何将html转换为文档而不丢失段落?,c#,html,html-agility-pack,C#,Html,Html Agility Pack,我试图从网站上获取文本。e、 g 它以纯文本形式导出到word。我是说没有 这使得它没有段落。我如何将其转换为文本,就像在原始网站上使用适当的段落一样 这是我获取文本的方法 private string yazial(string s) { string htmlContent = getsource(s); HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDoc

我试图从网站上获取文本。e、 g

它以纯文本形式导出到word。我是说没有 这使得它没有段落。我如何将其转换为文本,就像在原始网站上使用适当的段落一样

这是我获取文本的方法

       private string yazial(string s)
    {
        string htmlContent = getsource(s);
        HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
        document.LoadHtml(htmlContent);
        var nodlar = document.DocumentNode.SelectSingleNode("*//article").InnerHtml;

        var nodlar1 = document.DocumentNode.SelectSingleNode("*//article/div[@class='page-header']").InnerText;
        //lectSingleNode
        docyap(nodlar,nodlar1);
        return nodlar;
    }
这就是我尝试导出word文档的方法

  private void docyap(string s,string g)
    {
        Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
        oWord.Visible = true;
        object oMissing = System.Reflection.Missing.Value;

        Microsoft.Office.Interop.Word.Document wBelge = oWord.Documents.Add(ref oMissing, ref oMissing,
        ref oMissing, ref oMissing);    

        Microsoft.Office.Interop.Word.Paragraph baslik = wBelge.Paragraphs.Add(ref oMissing);
        object styleHeading = "Başlık 1";
        baslik.Range.set_Style(styleHeading);
        baslik.Range.Text = g; 

        baslik.Range.InsertParagraphAfter();
        Microsoft.Office.Interop.Word.Paragraph paragraf2;
        paragraf2 = wBelge.Paragraphs.Add(ref oMissing);
        paragraf2.Range.Text = s;
        paragraf2.Range.InsertParagraphAfter();           
        wBelge.SaveAs(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
我最后使用了like

           string yeni = nodlar.Replace("<p>", "    ").Replace("</p>","\n");
           yeni = System.Text.RegularExpressions.Regex.Replace(yeni, "<div(.*)</div>", string.Format(""));
           yeni = System.Text.RegularExpressions.Regex.Replace(yeni, "<div(.*)</a>", string.Format(""));
            yeni = Regex.Replace(yeni, @"<[^>]*>", String.Empty);
string yeni=nodlar.Replace(“”,”).Replace(“

”,“\n”); yeni=System.Text.RegularExpressions.Regex.Replace(yeni,“