public void ExtractBasic() { ExtractBasic_TestData[] tests = { new ExtractBasic_TestData("<html><title>test</title><img src='http://www.server.com/image.gif'></html>", "test"), new ExtractBasic_TestData("<html><title>", null), new ExtractBasic_TestData("<html><title>test", "test"), new ExtractBasic_TestData("<html><title>test\nrow</title><img src='http://www.server.com/image.gif'></html>", "test\nrow"), }; foreach (ExtractBasic_TestData test in tests) { HtmlPageInfo info = HtmlPageInfoExtractor.Extract(test._html); Console.WriteLine("Title: {0}", info.Title); Assert.AreEqual(test._title, info.Title); } }
public void linkFetch_Click(object sender, EventArgs e) { try { ContentPageParameters p = new ContentPageParameters(); p.UserAgent = SessionManager.GetCachedConfiguration("SnCore.Web.UserAgent", "SnCore/1.0"); Uri pageuri = new Uri(inputUrl.Text); string content = ContentPage.GetHttpContent(pageuri, p); HtmlPageInfo info = HtmlPageInfoExtractor.Extract(content); if (string.IsNullOrEmpty(info.Title)) { TransitPlace place = SessionManager.GetInstance <TransitPlace, int>( PlaceId, SessionManager.PlaceService.GetPlaceById); info.Title = place.Name; } inputName.Text = info.Title.Trim(); } catch (Exception ex) { throw new Exception(string.Format("Error retreiving {0}\n{1}", inputUrl.Text, ex.Message)); } }