换肤,控件美化,自定义messagebox,爬网页链接,脚本,和图片,本地书签,多选项卡
if (SelectType == "信息")
{
string RN = "\r\n";
string str = "";
str = "元素总数:" web1.Document.All.Count.ToString() RN;
str = "连接总数:" web1.Document.Links.Count.ToString() RN;
str = "图片总数:" web1.Document.Images.Count.ToString() RN;
str = "表单总数:" web1.Document.Forms.Count.ToString() RN;
str = "框架总数:" web1.Document.Window.Frames.Count.ToString() RN;
CusterFormControl("页面信息:", str, "", "", "", "");
}
if (SelectType =="图片")
{
StringBuilder strHTML = new StringBuilder();
strHTML.Append(string.Format("<h3>共{0}个图片</h3>", web1.Document.Images.Count));
strHTML.Append("<style>img{border:solid 1px blue; margin:5px;}</style>");
strHTML.Append("<table border=1 cellpadding=3 style=\"border-collapse:collapse;\">");
strHTML.Append("<tr><th>序号</th><th>图片</th><th>SRC</th><th>宽高</th></tr>");
int i = 1;
foreach (HtmlElement img in web1.Document.Images)
{
strHTML.Append("<tr>");
strHTML.Append(string.Format("<td>{0}</td>", i ));
strHTML.Append(string.Format("<td><img src=\"{0}\"></td>", img.GetAttribute("src")));
strHTML.Append(string.Format("<td><a href=\"{0}\">{0}</a></td>", img.GetAttribute("src")));
strHTML.Append(string.Format("<td>{0}*{1}</td>", img.OffsetRectangle.Width, img.OffsetRectangle.Height));
strHTML.Append("</tr>");
}
strHTML.Append("</table>");
web1.Document.Write(strHTML.ToString());
web1.Dock = DockStyle.Fill;
//System.Windows.Forms.WebBrowser webBrowser;
System.Windows.Forms.TabPage tabPage = new System.Windows.Forms.TabPage()
{
Text = "当前页面的所有图片"
};
tabPage.Controls.Add(web1);
this.TabControl1.Controls.Add(tabPage);
this.web1 = new WebBrowser();
}
if (SelectType =="连接")
{
StringBuilder strHTML = new StringBuilder();
strHTML.Append(string.Format("<h3>共{0}个连接</h3>", web1.Document.Links.Count));
strHTML.Append("<table border=1 cellpadding=3 style=\"border-collapse:collapse;\">");
strHTML.Append("<tr><th>序号</th><th>名称</th><th>href</th><th>target</th></tr>");
int i = 1;
foreach (HtmlElement link in web1.Document.Links)
{
strHTML.Append("<tr>");
strHTML.Append(string.Format("<td>{0}</td>", i ));
strHTML.Append(string.Format("<td>{0}</td>", link.InnerText));
strHTML.Append(string.Format("<td><a href=\"{0}\">{0}</a></td>", link.GetAttribute("href")));
strHTML.Append(string.Format("<td>{0}</td>", link.GetAttribute("target")));
strHTML.Append("</tr>");
}
strHTML.Append("</table>");
web1.Document.Write(strHTML.ToString());
web1.Dock = DockStyle.Fill;
System.Windows.Forms.TabPage tabPage;
tabPage = new System.Windows.Forms.TabPage()
{
Text = "当前页面的所有连接"
};
tabPage.Controls.Add(web1);
this.TabControl1.Controls.Add(tabPage);
this.web1 = new WebBrowser();
}
if (SelectType == "引用")
{
StringBuilder strHTML = new StringBuilder();
HtmlElementCollection elList = web1.Document.GetElementsByTagName("link");
strHTML.Append(string.Format("<h3>共{0}个LINK</h3>", elList.Count));
strHTML.Append("<table border=1 cellpadding=3 style=\"border-collapse:collapse;\">");
strHTML.Append("<tr><th>序号</th><th>href</th></tr>");
int i = 1;
foreach (HtmlElement el in elList)
{
string href = el.GetAttribute("href");
strHTML.Append("<tr>");
strHTML.Append(string.Format("<td>{0}</td>", i ));
strHTML.Append(string.Format("<td><a href=\"{0}\">{0}</a></td>", href.StartsWith("http") ? href : ("http://" web1.Url.Authority href)));
strHTML.Append("</tr>");
}
strHTML.Append("</table>");
elList = web1.Document.GetElementsByTagName("script");
i = 1;
strHTML.Append(string.Format("<h3>共{0}个SCRIPT</h3>", elList.Count));
strHTML.Append("<table border=1 cellpadding=3 style=\"border-collapse:collapse;\">");
strHTML.Append("<tr><th>序号</th><th>类型</th><th>内容</th></tr>");
foreach (HtmlElement el in elList)
{
string src = el.GetAttribute("src");
strHTML.Append("<tr>");
strHTML.Append(string.Format("<td>{0}</td>", i ));
strHTML.Append(string.Format("<td>{0}</td>", src == "" ? "嵌入脚本" : "外部脚本"));
if (src.Trim() != "")
{
strHTML.Append(string.Format("<td><a href=\"{0}\">{0}</a></td>", src.StartsWith("http") ? src : ("http://" web1.Url.Authority src)));
}
else
{
strHTML.Append(string.Format("<td><pre>{0}</pre></td>", el.InnerHtml));
}
strHTML.Append("</tr>");
}
strHTML.Append("</table>");
web1.Document.Write(strHTML.ToString());
web1.Dock = DockStyle.Fill;
System.Windows.Forms.TabPage tabPage = new System.Windows.Forms.TabPage()
{
Text = "当前页面的所有引用"
};
tabPage.Controls.Add(web1);
this.TabControl1.Controls.Add(tabPage);
this.web1 = new WebBrowser();
评论