private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url != this.webBrowser.Document.Url) { return; } string encode = this.webBrowser.Document.Encoding; StreamReader sr = new StreamReader(this.webBrowser.DocumentStream, Encoding.GetEncoding(encode)); string html = sr.ReadToEnd(); //Html2Article.LimitCount = 100; //Html2Article.Depth = 8; // 设置是否使用正文追加模式 Html2Article.AppendMode = this.appendCheckBox.CheckState == CheckState.Checked; Stopwatch sw = new Stopwatch(); sw.Start(); // 将Html解析为Article结构化数据 Article article = Html2Article.GetArticle(html); sw.Stop(); msgLabel.Text = "提取耗时:" + Environment.NewLine + sw.ElapsedMilliseconds + "毫秒"; this.publishDateTextBox.Text = article.PublishDate.ToString(); this.titleTextBox.Text = article.Title; this.contentTextBox.Text = article.Content; string articleHtml = UrlUtility.FixUrl(this.urlTextBox.Text, article.ContentWithTags); this.contentWebBrowser.DocumentText = articleHtml; ResetState(); }
public void FixUrl() { string baseUrl = "http://www.stan.com"; string html = "<a href='http://www.a.com/a.html'></a>\r\n<img src='new.jpg' />info"; string result = UrlUtility.FixUrl(baseUrl, html); Assert.AreEqual("<a href='http://www.a.com/a.html'></a>\r\n<img src=\"http://www.stan.com/new.jpg\" />info", result); }
/// <summary> /// Tests the connection to the epistle server.<para> </para> /// Returns <c>true</c> if the connection could be established or <c>false</c> if the server did not respond. /// </summary> /// <returns>Whether the connection to the epistle server could be established successfully or not.</returns> public async Task <bool> TestConnection(string serverUrl = null) { try { var restClient = new RestClient(UrlUtility.FixUrl(serverUrl) ?? UrlUtility.EpistleBaseUrl); var request = new RestRequest( method: Method.Get, resource: new Uri("marco", UriKind.Relative) ); var response = await restClient.ExecuteAsync(request).ConfigureAwait(false); return(response?.Content.ToLower() == "polo"); } catch { return(false); } }