关键字挖掘机源码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Net;using System.Text;using System.Text.RegularExpressions;using System.Threading;using System.Windows.Forms;namespace KeyWordsExc{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } Thread t1; private void baidu_Click(object sender, EventArgs e) { Config.WriteIniData("KeyWord", "key", txtInputKey.Text.Trim(), Application.StartupPath @"\config\config.ini"); Config.WriteIniData("Rule", "rule", txtFilter.Text.Trim(), Application.StartupPath @"\config\config.ini"); Config.WriteIniData("MaxPage", "maxpage", txtCount.Text.Trim(), Application.StartupPath @"\config\config.ini"); Config.WriteIniData("MaxChar", "maxchar", txtMaxKey.Text.Trim(), Application.StartupPath @"\config\config.ini"); dataGridView1.Rows.Clear(); t1 = new Thread(new ThreadStart(Thread1)); t1.Priority = ThreadPriority.BelowNormal; t1.Start(); } private void stop_Click(object sender, EventArgs e) { t1.Abort(); } public void Thread1() { int itotal = 0; int num = int.Parse(txtCount.Text);//搜索条数 string sfilter = txtFilter.Text; string[] sfilters=null; if (sfilter.Trim() != "") { sfilters=sfilter.Trim().Split(','); } string[] arrKey = txtInputKey.Text.Trim().TrimEnd(',').Split(','); for (int iCountKey = 0; iCountKey < arrKey.Length; iCountKey ) { for (int ipage = 0; ipage < num; ipage ) { string url = "http://www.baidu.com/s?wd=" arrKey[iCountKey].Trim() "&rn=" num "&pn=" ipage * 9; string html = search(url, "utf-8"); BaiduSearch baidu = new BaiduSearch(); if (!string.IsNullOrEmpty(html)) { int count = baidu.GetSearchCount(html);//搜索条数 if (count > 0) { List<Keyword> keywords = baidu.GetKeywords(html, arrKey[iCountKey].Trim()); //dataGridView1.DataSource = keywords; for (int icout = 0; icout < keywords.Count; icout ) { try { itotal ; this.Invoke((EventHandler)delegate { ltotal.Text = itotal.ToString(); DataGridViewRow drs = new DataGridViewRow(); DataGridViewTextBoxCell txt_id = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell txt_word = new DataGridViewTextBoxCell(); txt_id.Value = itotal;// keywords[icout].ID; txt_word.Value = keywords[icout].KeyWord; drs.Cells.Add(txt_id); drs.Cells.Add(txt_word); bool isAdd = true; if (keywords[icout].KeyWord.Length > int.Parse(txtMaxKey.Text)) isAdd = false; for (int ifi = 0; ifi < sfilters.Length; ifi ) { if (keywords[icout].KeyWord.IndexOf(sfilters[ifi].ToString()) >= 0) { isAdd = false; } } if (dataGridView1.Rows.Count > 1 && isAdd) foreach (DataGridViewRow dgvr in dataGridView1.Rows) { if (dgvr.Cells[0].Value != null) { if (dgvr.Cells["KeyWord"].Value.ToString().Trim() == keywords[icout].KeyWord.Trim() || keywords[icout].KeyWord.Length > int.Parse(txtMaxKey.Text)) isAdd = false; } } if (isAdd) dataGridView1.Rows.Add(drs); }); } catch { } } } } } } MessageBox.Show("生成完成!"); } private void google_Click(object sender, EventArgs e) { int num = 100; string url = "http://www.google.com.hk/search?hl=zh-CN&source=hp&q=" txtInputKey.Text.Trim() "&aq=f&aqi=&aql=&oq=&num=" num ""; string html = search(url, "utf-8"); if (!string.IsNullOrEmpty(html)) { googleSearch google = new googleSearch(); List<Keyword> keywords = google.GetKeywords(html, txtInputKey.Text.Trim()); //dataGridView1.Columns[0]..Width = 600; dataGridView1.DataSource = keywords; //dataGridView1.AutoSizeColumnsMode } } /// <summary> /// 搜索处理 /// </summary> /// <param name="url">搜索网址</param> /// <param name="Chareset">编码</param> public string search(string url, string Chareset) { HttpState result = new HttpState(); Uri uri = new Uri(url); HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); myHttpWebRequest.UseDefaultCredentials = true; myHttpWebRequest.ContentType = "text/html"; myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50215;)"; myHttpWebRequest.Method = "GET"; myHttpWebRequest.CookieContainer = new CookieContainer(); try { HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.GetResponse(); // 从 ResponseStream 中读取HTML源码并格式化 add by cqp result.Html = readResponseStream(response, Chareset); result.CookieContainer = myHttpWebRequest.CookieContainer; return result.Html; } catch (Exception ex) { return ex.ToString(); } } public string readResponseStream(HttpWebResponse response, string Chareset) { string result = ""; using (StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(Chareset))) { result = formatHTML(responseReader.ReadToEnd()); } return result; } /// <summary> /// 描述:格式化网页源码 /// /// </summary> /// <param name="htmlContent"></param> /// <returns></returns> public string formatHTML(string htmlContent) { string result = ""; result = htmlContent.Replace("»", "").Replace(" ", "") .Replace("©", "").Replace("/r", "").Replace("/t", "") .Replace("/n", "").Replace("&", "&"); return result; } public class BaiduSearch { protected string uri = "http://www.baidu.com/s?wd="; protected Encoding queryEncoding = Encoding.GetEncoding("gb2312"); protected Encoding pageEncoding = Encoding.GetEncoding("gb2312"); protected string resultPattern = @"(?<=找到相关结果[约]?)[0-9,]*?(?=个)"; public int GetSearchCount(string html) { int result = 0; string searchcount = string.Empty; Regex regex = new Regex(resultPattern); Match match = regex.Match(html); if (match.Success) { searchcount = match.Value; } else { searchcount = "0"; } if (searchcount.IndexOf(",") > 0) { searchcount = searchcount.Replace(",", string.Empty); } int.TryParse(searchcount, out result); return result; } public List<Keyword> GetKeywords(string html, string word) { int i = 1; List<Keyword> keywords = new List<Keyword>(); //string ss="<h3 class=\"t\"><a.*?href=\"(?<url>.*?)\".*?>(?<content>.*?)</a>"; string ss = ">(?<content>.*?)</a></h3>"; MatchCollection mcTable = Regex.Matches(html,ss); foreach (Match mTable in mcTable) { if (mTable.Success) { Keyword keyword = new Keyword(); keyword.ID = i ; keyword.KeyWord = Regex.Replace(mTable.Groups["content"].Value, "<[^>]*>", string.Empty); //keyword.Link = mTable.Groups["url"].Value; keywords.Add(keyword); } } return keywords; } } public class googleSearch { public List<Keyword> GetKeywords(string html, string word) { int i = 1; List<Keyword> keywords = new List<Keyword>(); Regex regTable = new Regex("<h3 class=\"r\"><a.*?href=\"(?<url>.*?)\".*?>(?<content>.*?)</a>", RegexOptions.IgnoreCase); Regex regA = new Regex(@"(?is)<a/b[^>]*?href=(['""]?)(?<link>[^'""/s>] )/1[^>]*>(?<title>.*?)</a>", RegexOptions.IgnoreCase); MatchCollection mcTable = regTable.Matches(html); foreach (Match mTable in mcTable) { if (mTable.Success) { Keyword keyword = new Keyword(); keyword.ID = i ; keyword.KeyWord = Regex.Replace(mTable.Groups["content"].Value, "<[^>]*>", string.Empty); //keyword.Link = mTable.Groups["url"].Value; keywords.Add(keyword); } } return keywords; } } private void btnOutPut_Click(object sender, EventArgs e) { SaveFileDialog saveFile1 = new SaveFileDialog(); saveFile1.Filter = "文本文件(.txt)|*.txt"; saveFile1.FilterIndex = 1; if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveFile1.FileName.Length > 0) { System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFile1.FileName, false); try { string sword = ""; foreach(DataGridViewRow dr in dataGridView1.Rows) { sword = dr.Cells["KeyWord"].Value.ToString(); sw.WriteLine(sword); } } catch { //throw; } finally { sw.Close(); } } } private void Form1_Load(object sender, EventArgs e) { this.skinEngine1.SkinFile = "config\\MP10.ssk"; string sKeyword = Config.ReadIniData("KeyWord", "key", "", Application.StartupPath @"\config\config.ini"); txtInputKey.Text = sKeyword; string sRule = Config.ReadIniData("Rule", "rule", "", Application.StartupPath @"\config\config.ini"); txtFilter.Text = sRule; string sCount = Config.ReadIniData("MaxPage", "maxpage", "", Application.StartupPath @"\config\config.ini"); txtCount.Text=sCount; string sMaxchar = Config.ReadIniData("MaxChar", "maxchar","", Application.StartupPath @"\config\config.ini"); txtMaxKey.Text=sMaxchar; } }}
下载C# 关键字挖掘机源码下载(亲测可用)用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论