using Ruanm.Framework.Http;
using HtmlAgilityPack;
public string html = string.Empty;
public string yhfx_evaluate_1, yhfx_evaluate_2, yhfx_evaluate_3, yhfx_evaluate_4, yhfx_evaluate_5, yhfx_evaluate_6, yhfx_evaluate_7;
public string changweiguanjianci, changweiguanjianci_count;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
html= HttpHelper.DownLoadHtml("https://data.chinaz.com/keyword/analysis/%E7%9C%BC%E5%BD%B1");
if (string.IsNullOrEmpty(html))
{ }
HtmlDocument document = new HtmlDocument();
document.LoadHtml(html);
//SEO优化分析
#region SEO优化分析
string evaluate_1 = "//*[@id='evaluate_1']";
HtmlNode Html_evaluate_1 = document.DocumentNode.SelectSingleNode(evaluate_1);
yhfx_evaluate_1 = Html_evaluate_1.InnerText;
string evaluate_2 = "//*[@id='evaluate_2']";
HtmlNode Html_evaluate_2 = document.DocumentNode.SelectSingleNode(evaluate_2);
yhfx_evaluate_2 = Html_evaluate_2.InnerText;
string evaluate_3 = "//*[@id='evaluate_3']";
HtmlNode Html_evaluate_3 = document.DocumentNode.SelectSingleNode(evaluate_3);
yhfx_evaluate_3 = Html_evaluate_3.InnerText;
string evaluate_4 = "//*[@id='evaluate_4']";
HtmlNode Html_evaluate_4 = document.DocumentNode.SelectSingleNode(evaluate_4);
yhfx_evaluate_4 = Html_evaluate_4.InnerText;
string evaluate_5 = "//*[@id='evaluate_5']";
HtmlNode Html_evaluate_5 = document.DocumentNode.SelectSingleNode(evaluate_5);
yhfx_evaluate_5 = Html_evaluate_5.InnerText;
string evaluate_6 = "//*[@id='evaluate_6']";
HtmlNode Html_evaluate_6 = document.DocumentNode.SelectSingleNode(evaluate_6);
yhfx_evaluate_6 = Html_evaluate_6.InnerText;
string evaluate_7 = "//*[@id='evaluate_7']";
HtmlNode Html_evaluate_7 = document.DocumentNode.SelectSingleNode(evaluate_7);
yhfx_evaluate_7 = Html_evaluate_7.InnerText;
#endregion
//左边三个层
#region 左边三个层
string Module_Columns_left = "//*[@class='Module-Columns z-fl']";
HtmlNodeCollection Module_Columns_left_list = document.DocumentNode.SelectNodes(Module_Columns_left);
if (Module_Columns_left_list != null)
{
foreach (HtmlNode node in Module_Columns_left_list)
{
string firstHtml = node.OuterHtml;
HtmlDocument documentChild = new HtmlDocument();
documentChild.LoadHtml(firstHtml);
//长尾关键词
string css_Module_Columns_left_list_title = "//*[@class='MT-text z-fl']";
HtmlNode css_Module_Columns_left_list_title_1 = documentChild.DocumentNode.SelectSingleNode(css_Module_Columns_left_list_title);
if (css_Module_Columns_left_list_title_1 != null)
changweiguanjianci = css_Module_Columns_left_list_title_1.InnerText;
//175490个
string css_Module_Columns_left_list_count = "//*[@class='z-pt3 z-fr c-36']";
HtmlNode css_Module_Columns_left_list_count_1 = documentChild.DocumentNode.SelectSingleNode(css_Module_Columns_left_list_count);
if (css_Module_Columns_left_list_count_1 != null)
changweiguanjianci_count = css_Module_Columns_left_list_count_1.InnerText;
//百度自然排名的 查看全部
string baidu_Rank_SeaAll_Path = "//*[@class='z-pt4 clearfix']/a";
HtmlNode baidu_Rnak_SeaAll_Path_Node = documentChild.DocumentNode.SelectSingleNode(baidu_Rank_SeaAll_Path);
if (baidu_Rnak_SeaAll_Path_Node != null)
{
string baidu_Rnak_SeaAll_Path_Href = baidu_Rnak_SeaAll_Path_Node.Attributes["href"].Value;
}
//div ul li class='row listx clearfix'
string Module_Columns_left_li = "//*[@class='row listx clearfix']";
HtmlNodeCollection Module_Columns_left_li_list = documentChild.DocumentNode.SelectNodes(Module_Columns_left_li);
if (Module_Columns_left_li_list != null)
{
foreach (HtmlNode liNode in Module_Columns_left_li_list)
{
string liHtml = liNode.OuterHtml;
HtmlDocument documentLiHtml = new HtmlDocument();
documentLiHtml.LoadHtml(liHtml);
if (changweiguanjianci == "百度自然排名")
{
string baidu_Rank_Path = "//*[@class='col-66']";
HtmlNode baidu_Rank_Path_Node = documentLiHtml.DocumentNode.SelectSingleNode(baidu_Rank_Path);
if (baidu_Rank_Path_Node != null)
{
string baidu_Rank_Value = baidu_Rank_Path_Node.InnerText; //百度自然排名 序号
}
string baidu_Rank_Title_Path = "//div/a";
HtmlNode baidu_Rank_Title_Node = documentLiHtml.DocumentNode.SelectSingleNode(baidu_Rank_Title_Path);
if (baidu_Rank_Title_Node != null)
{
string baidu_Rank_Title = baidu_Rank_Title_Node.InnerText;
string baidu_Rank_Title_Href = baidu_Rank_Title_Node.Attributes["href"].Value;
}
}
else //长尾关键词 //相关搜索词 列表数据
{
//关键词
// / html / body / div[3] / div[4] / div[2] / div[2] / div[1] / ul / li[4] / div[3] / span / a
string gjcPath = "//div/a";
HtmlNode gjcPath_Node = documentLiHtml.DocumentNode.SelectSingleNode(gjcPath);
if (gjcPath_Node != null)
{
string gjcPath_html = gjcPath_Node.InnerText;
HtmlNode gjcPath_Node_Href = documentLiHtml.DocumentNode.SelectSingleNode(gjcPath);
string gjcPath_html_Href = gjcPath_Node_Href.Attributes["href"].Value;
}
else
{
string gjcPath_html = "";
string gjcPath_html_Href = "";
}
//全网指数
string qwzxPath = "//div/span";
HtmlNode qwzxPath_Node = documentLiHtml.DocumentNode.SelectSingleNode(qwzxPath);
if (qwzxPath_Node != null)
{
string qwzxPath_html = qwzxPath_Node.InnerText;
}
else
{
string qwzxPath_html = "";
}
//长尾词数
string cwcsPath = "//div/span/a";
HtmlNode cwcsPath_Node = documentLiHtml.DocumentNode.SelectSingleNode(cwcsPath);
if (cwcsPath_Node != null)
{
string cwcsPath_html = cwcsPath_Node.InnerText;
}
else
{
}
}
}
}
}
}
#endregion
//右边三个层
#region 右边三个层
string Module_Columns_right = "//*[@class='Module-Columns z-fr']";
HtmlNodeCollection Module_Columns_right_list = document.DocumentNode.SelectNodes(Module_Columns_right);
if (Module_Columns_right_list != null)
{
foreach (HtmlNode node in Module_Columns_right_list)
{
string firstHtml = node.OuterHtml;
HtmlDocument documentChild = new HtmlDocument();
documentChild.LoadHtml(firstHtml);
//长尾关键词
string css_Module_Columns_left_list_title = "//*[@class='MT-text z-fl']";
HtmlNode css_Module_Columns_left_list_title_1 = documentChild.DocumentNode.SelectSingleNode(css_Module_Columns_left_list_title);
if (css_Module_Columns_left_list_title_1 != null)
changweiguanjianci = css_Module_Columns_left_list_title_1.FirstChild.InnerText;
//175490个
string css_Module_Columns_left_list_count = "//*[@class='z-pt3 z-fr c-36']";
HtmlNode css_Module_Columns_left_list_count_1 = documentChild.DocumentNode.SelectSingleNode(css_Module_Columns_left_list_count);
if (css_Module_Columns_left_list_count_1 != null)
changweiguanjianci_count = css_Module_Columns_left_list_count_1.InnerText;
//百度自然排名的 查看全部
string baidu_Rank_SeaAll_Path = "//*[@class='z-pt4 clearfix']/a";
HtmlNode baidu_Rnak_SeaAll_Path_Node = documentChild.DocumentNode.SelectSingleNode(baidu_Rank_SeaAll_Path);
if (baidu_Rnak_SeaAll_Path_Node != null)
{
string baidu_Rnak_SeaAll_Path_Href = baidu_Rnak_SeaAll_Path_Node.Attributes["href"].Value;
}
//搜索引擎竞价 数量
string bidding_count_Path = "//*[@class='z-pt3 fz12 c-36']";
HtmlNode bidding_count_Path_Node = documentChild.DocumentNode.SelectSingleNode(bidding_count_Path);
if (bidding_count_Path_Node != null)
{
string bidding_count_Path_Text = bidding_count_Path_Node.InnerText;
}
//搜索引擎竞价 百度PC
string bidding_navbar_Path = "//*[@class='bidding-navbar clearfix']/a";
HtmlNode bidding_navbar_Path_Node = documentChild.DocumentNode.SelectSingleNode(bidding_navbar_Path);
if (bidding_navbar_Path_Node != null)
{
string bidding_navbar_Text = bidding_navbar_Path_Node.InnerText; //百度PC
string bidding_navbar_Href = bidding_navbar_Path_Node.Attributes["href"].Value;
}
//div ul li class='row listx clearfix'
string Module_Columns_left_li = "//*[@class='row listx clearfix']";
if (changweiguanjianci == "搜索引擎竞价")
{
Module_Columns_left_li = "//*[@class='row listx clearfix ']";
}
else
{
Module_Columns_left_li = "//*[@class='row listx clearfix']";
}
HtmlNodeCollection Module_Columns_left_li_list = documentChild.DocumentNode.SelectNodes(Module_Columns_left_li);
if (Module_Columns_left_li_list != null)
{
foreach (HtmlNode liNode in Module_Columns_left_li_list)
{
string liHtml = liNode.OuterHtml;
HtmlDocument documentLiHtml = new HtmlDocument();
documentLiHtml.LoadHtml(liHtml);
if (changweiguanjianci == "搜索引擎竞价")
{
//标题
string SEO_Bidding_Title_Path = "//*[@class='nofoldtxt']/a";
HtmlNode SEO_Bidding_Title_Path_Node = documentLiHtml.DocumentNode.SelectSingleNode(SEO_Bidding_Title_Path);
if (SEO_Bidding_Title_Path_Node != null)
{
string SEO_Bidding_Title_Path_Value = SEO_Bidding_Title_Path_Node.InnerText; //搜索引擎竞价 标题
string SEO_Bidding_Title_Path_Href = SEO_Bidding_Title_Path_Node.Attributes["href"].Value;//搜索引擎竞价 链接
}
//公司名称
string SEO_Bidding_Company_Path = "//*[@class='col-11']/p[1]";
HtmlNode SEO_Bidding_Company_Path_Node = documentLiHtml.DocumentNode.SelectSingleNode(SEO_Bidding_Company_Path);
if (SEO_Bidding_Company_Path_Node != null)
{
string SEO_Bidding_Company = SEO_Bidding_Company_Path_Node.InnerText;
}
//公司网址
string SEO_Bidding_Domain_Path = "//*[@class='col-11']/p[2]";
HtmlNode SEO_Bidding_Domain_Path_Node = documentLiHtml.DocumentNode.SelectSingleNode(SEO_Bidding_Domain_Path);
if (SEO_Bidding_Domain_Path_Node != null)
{
string SEO_Bidding_Domain = SEO_Bidding_Domain_Path_Node.InnerText;
}
}
else //长尾关键词 //相关搜索词 列表数据
{
//关键词
// / html / body / div[3] / div[4] / div[2] / div[2] / div[1] / ul / li[4] / div[3] / span / a
string gjcPath = "//div/a";
HtmlNode gjcPath_Node = documentLiHtml.DocumentNode.SelectSingleNode(gjcPath);
if (gjcPath_Node != null)
{
string gjcPath_html = gjcPath_Node.InnerText;
HtmlNode gjcPath_Node_Href = documentLiHtml.DocumentNode.SelectSingleNode(gjcPath);
string gjcPath_html_Href = gjcPath_Node_Href.Attributes["href"].Value;
}
else
{
string gjcPath_html = "";
string gjcPath_html_Href = "";
}
//全网指数
string qwzxPath = "//div/span";
HtmlNode qwzxPath_Node = documentLiHtml.DocumentNode.SelectSingleNode(qwzxPath);
if (qwzxPath_Node != null)
{
string qwzxPath_html = qwzxPath_Node.InnerText;
}
else
{
string qwzxPath_html = "";
}
//长尾词数
string cwcsPath = "//div/span/a";
HtmlNode cwcsPath_Node = documentLiHtml.DocumentNode.SelectSingleNode(cwcsPath);
if (cwcsPath_Node != null)
{
string cwcsPath_html = cwcsPath_Node.InnerText;
}
else
{
}
}
}
}
}
}
#endregion
}
}