保存html更改

时间:2012-02-22 13:43:47

标签: c# html-parsing html-agility-pack

我的问题是我想要改变电子邮件的html中某些人的src值。所有这些都已经完成,我使用EWS api建立连接,并使用html agility pack进行解析。任何人都知道如何获取html与我对图像中的src值所做的更改?

    public static string parsearHtml(string body,Item item, ArrayList contentIDS, ArrayList urls)
    {
        string SRC = "";
        int indice = 0;
        string retorno = "";
        //Console.WriteLine(body);

        HtmlDocument email = new HtmlDocument();
        email.LoadHtml(body);

        foreach (HtmlNode img in email.DocumentNode.SelectNodes("//img"))
        {
            SRC = img.GetAttributeValue("src", null);
            for (int i = 0; i < contentIDS.Count; i++)
            {
                if (SRC.Equals(contentIDS[i].ToString()))
                {
                    indice = i;
                    break;
                }
            }

            img.SetAttributeValue("src", urls[indice].ToString());
            Console.WriteLine(img.GetAttributeValue("src", null));//in here i get the the attribute and its change so the changing of src values is working
            //i tried email.save(retorno) but got error for empty path
            //so i tried email.save(body) but got error for illegar characters in path
        }

        return retorno;

   }

1 个答案:

答案 0 :(得分:0)

您可以使用

获取整个html字符串
email.DocumentNode.OuterHtml

HTML Agility Pack HtmlDocument Show All Html?

处回答了类似的问题