9月特惠 限时2折
全网云主机爆款特惠,新用户限时享低至2折优惠
https://www.aliyun.com/acts/limit-buy?userCode=ge65ec6y
【主机爆款特惠】限时优惠 低至3折
全网云主机爆款特惠,新用户限时享低至3折优惠
https://www.aliyun.com/acts/hotsale?userCode=ge65ec6y
企业级云服务器5折特惠
企业级云服务器首购3年仅3折
https://promotion.aliyun.com/ntms/act/enterprise-discount.html?userCode=ge65ec6y
【全民云计算】云主机低至4折
爆款云服务器低至4折,1核1G¥366/年
https://promotion.aliyun.com/ntms/act/qwbk.html?userCode=ge65ec6y
【25%-40%返佣】阿里云应用中心,一站式企业服务
建站,商标,工商财税,小程序,OA等多款热门产品全力推荐,小程序更是低至9.9元!
https://ac.aliyun.com/pages/bkshare?userCode=ge65ec6y
【阿里云新用户】云通信专享8折
https://www.aliyun.com/acts/alicomcloud/new-discount?userCode=ge65ec6y
【商标注册服务】低至680元
专业专注 极速申报 最快1分钟递交到商标局
https://tm.aliyun.com/?userCode=ge65ec6y
享受更多优惠,请联系17303219823(微信号),有惊喜!
注意添加引用,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Winista.Text.HtmlParser;
using Winista.Text.HtmlParser.Lex;
using Winista.Text.HtmlParser.Util;
using Winista.Text.HtmlParser.Tags;
using Winista.Text.HtmlParser.Filters;
namespace HTMLParser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
AddUrl();
}
private void btnParser_Click(object sender, EventArgs e)
{
#region 获得网页的html
try
{
txtHtmlWhole.Text = "";
string url = CBUrl.SelectedItem.ToString().Trim();
System.Net.WebClient aWebClient = new System.Net.WebClient();
aWebClient.Encoding = System.Text.Encoding.Default;
string html = aWebClient.DownloadString(url);
txtHtmlWhole.Text = html;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion
#region 分析网页html节点
Lexer lexer = new Lexer(this.txtHtmlWhole.Text);
Parser parser = new Parser(lexer);
NodeList htmlNodes = parser.Parse(null);
this.treeView1.Nodes.Clear();
this.treeView1.Nodes.Add("root");
TreeNode treeRoot = this.treeView1.Nodes[0];
for (int i = 0; i < htmlNodes.Count; i++)
{
this.RecursionHtmlNode(treeRoot, htmlNodes[i], false);
}
#endregion
}
private void RecursionHtmlNode(TreeNode treeNode, INode htmlNode, bool siblingRequired)
{
if (htmlNode == null || treeNode == null) return;
TreeNode current = treeNode;
TreeNode content ;
//current node
if (htmlNode is ITag)
{
ITag tag = (htmlNode as ITag);
if (!tag.IsEndTag())
{
string nodeString = tag.TagName;
if (tag.Attributes != null && tag.Attributes.Count > 0)
{
if (tag.Attributes["ID"] != null)
{
nodeString = nodeString + " { id=\"" + tag.Attributes["ID"].ToString() + "\" }";
}
if (tag.Attributes["HREF"] != null)
{
nodeString = nodeString + " { href=\"" + tag.Attributes["HREF"].ToString() + "\" }";
}
}
current = new TreeNode(nodeString);
treeNode.Nodes.Add(current);
}
}
//获取节点间的内容
if (htmlNode.Children != null && htmlNode.Children.Count > 0)
{
this.RecursionHtmlNode(current, htmlNode.FirstChild, true);
content = new TreeNode(htmlNode.FirstChild.GetText());
treeNode.Nodes.Add(content);
}
//the sibling nodes
if (siblingRequired)
{
INode sibling = htmlNode.NextSibling;
while (sibling != null)
{
this.RecursionHtmlNode(treeNode, sibling, false);
sibling = sibling.NextSibling;
}
}
}
private void AddUrl()
{
CBUrl.Items.Add("http://www.hao123.com");
CBUrl.Items.Add("http://www.sina.com");
CBUrl.Items.Add("http://www.heuet.edu.cn");
}
}
}
下载地址:https://download.youkuaiyun.com/download/liyonghui__521/10945039
如何获取不到,请添加QQ649736983
展示界面: