Click here to Skip to main content
15,882,055 members
Articles / Programming Languages / C#

Harvesting Web Content into MHTML Archive

Rate me:
Please Sign up or sign in to vote.
4.69/5 (14 votes)
18 Feb 20068 min read 61.7K   729   49  
Capture and archive web resources by saving them in RFC-2557 (MHTML) compliant format. This library includes a framework for augmenting the capture process and allowing programmatic control, from downloading through saving. A replacement for CDOSYS/CDONTS.
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Rilling.MhtmlLib.Media.Handlers;
using Rilling.MhtmlLib.Media.Artifacts;
using System.Net;

namespace Rilling.Web.Mhtml.TestHarness
{
	[TestFixture]
	public class HtmlContentHandlerTest
	{
		private HtmlContentHandler m_testObj = null;

		[SetUp]
		public void Init()
		{
			m_testObj = new HtmlContentHandler();
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Call_CreateArtifact_NullParam()
		{
			m_testObj.CreateArtifact(null);
		}

		[Test]
		public void Call_CreateArtifact()
		{
			Uri url = new Uri("http://mhtml.sourceforge.net/unittest_samples/HtmlSample.html");
			HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
			HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

			HtmlArtifact result = (HtmlArtifact)m_testObj.CreateArtifact(resp);

			Assert.IsNotNull(result);
			Assert.IsNotNull(result.BaseStream);
			Assert.AreEqual("text/html", result.ContentType);
			Assert.AreEqual(5646, result.DataSize);
			Assert.AreEqual(url.ToString(), result.Location.ToString());
			Assert.AreEqual("iso-8859-1", result.CharacterSet);
			Assert.IsNotNull(result.Encoding);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions