【问题标题】:Screen scrape to email with full url for images and css屏幕抓取到带有图像和 css 完整 URL 的电子邮件
【发布时间】:2011-08-08 23:00:45
【问题描述】:

我正在屏幕抓取网页并将其作为 html 电子邮件发送。

操纵 html 为所有图像和 css 文件设置完整 http 地址的最简单/最佳方法是什么?

当前方法类似于(手动输入)+这很容易出错。

string html = rawHtml.replace("=\"", "=\"" + Request["SERVER_NAME"]);

.
.

这是我们使用 GET 进行屏幕抓取的当前函数

public static string WebGet(string address)
{
    string result = "";
    using (WebClient client = new WebClient())
    {
        using (StreamReader reader = new StreamReader(client.OpenRead(address)))
        {
            string s = reader.ReadToEnd();
            result = s;
        }
    }

    return result;
}

【问题讨论】:

  • 所以您想将相对 URL 解析为绝对 URL,即 img src="/images/img.jpg" 变为 img src="http://example.com/images/img.jpg,CSS(和链接)类似?

标签: asp.net asp.net-mvc screen-scraping


【解决方案1】:

听起来你需要一个 HTML 解析器。使用解析器解析 html 字符串后,您可以执行轻松操作 DOM 的命令,因此您可以找到所有 img 元素,检查它们的 src 并在需要时附加 Request["SERVER_NAME"]。

我不会在 ASP 中编码,但我发现了这个:

http://htmlagilitypack.codeplex.com/

这是我发现的一篇有用的文章,解释了如何使用它:

http://www.4guysfromrolla.com/articles/011211-1.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 2013-06-01
    • 2015-03-15
    • 2011-02-21
    相关资源
    最近更新 更多