private void button1_Click(object sender, EventArgs e)
{
try
if (this.txtUrl.Text.Trim().Length == 0)
("請輸入主入口地址!");
}
else
//這裡獲取GetWebContent方法的結果
string webContent = GetWebContent(this.txtUrl.Text.Trim());
//宣告一個WebBrowser
WebBrowser webBrowser = new WebBrowser();
webBrowser.Navigate("about:blank");
//將GetWebContent方法返回的結果轉化為HtmlDocument,就可以正確處理網頁中的元素了。
HtmlDocument htmlDoc = webBrowser.Document.OpenNew(true);
htmlDoc.Write(webContent);
//獲取網頁中Body中的Html程式碼
string outerHtml = htmlDoc.Body.OuterHtml;
//獲取網頁的標題
string outerTitle=htmlDoc.Title;
this.txtDocumentTitle.Text = outerTitle;
this.txtDocumentConent.Text = outerHtml;
catch (Exception ex)
MessageBox.Show(ex.Message);
private void button1_Click(object sender, EventArgs e)
{
try
{
if (this.txtUrl.Text.Trim().Length == 0)
{
("請輸入主入口地址!");
}
else
{
//這裡獲取GetWebContent方法的結果
string webContent = GetWebContent(this.txtUrl.Text.Trim());
//宣告一個WebBrowser
WebBrowser webBrowser = new WebBrowser();
webBrowser.Navigate("about:blank");
//將GetWebContent方法返回的結果轉化為HtmlDocument,就可以正確處理網頁中的元素了。
HtmlDocument htmlDoc = webBrowser.Document.OpenNew(true);
htmlDoc.Write(webContent);
//獲取網頁中Body中的Html程式碼
string outerHtml = htmlDoc.Body.OuterHtml;
//獲取網頁的標題
string outerTitle=htmlDoc.Title;
this.txtDocumentTitle.Text = outerTitle;
this.txtDocumentConent.Text = outerHtml;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}