【问题标题】:save html changes保存 html 更改
【发布时间】:2012-03-12 20:27:13
【问题描述】:

我的问题是我想在收到的电子邮件的 html 中更改一些 src 值。所有这一切都已经完成,我使用 EWS api 建立连接并使用 html 敏捷包进行解析。任何人都知道如何通过我对图像中的 src 值所做的更改来获取 html?

    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;

   }

【问题讨论】:

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


    【解决方案1】:

    你可以得到整个html字符串

    email.DocumentNode.OuterHtml
    

    HTML Agility Pack HtmlDocument Show All Html?回答了类似的问题

    【讨论】:

    • thx 但无论如何都要使用内存流解决它,感谢您的帖子。顺便说一句,有任何想法如何在 html 中获取外部图像。是的,我只使用附件进行了解决。知道如何获取参考图像并将其转换为 c# 中的字节数组或图像对象吗?
    • 我正在使用 htmlagilitypack,我知道如何获取图像的 src 值,但是我如何获取和存储该物理图像。不想将其存储在磁盘中。就像存储在字节数组中的附件一样。
    • 为了将图像下载到字节数组,您可以使用 WebClient 类。 geekswithblogs.net/whiletrue/archive/2010/03/11/… 有一个简单的例子
    猜你喜欢
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    • 2020-10-29
    相关资源
    最近更新 更多