public void Gather(string domain) { //string pageUrl = "http://top.baidu.com/buzz.php?p=top_keyword"; //string pageUrl = "http://seo.chinaz.com/?host="+domain; string pageUrl = "http://www.aizhan.com/siteall/" + domain + "/"; WebClient wc = new WebClient(); byte[] pageSourceBytes = wc.DownloadData(new Uri(pageUrl)); //string pageSource = Encoding.GetEncoding("gb2312").GetString(pageSourceBytes); string pageSource = Encoding.GetEncoding("utf-8").GetString(pageSourceBytes); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageSource); //HtmlNodeCollection keyNodes = doc.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[9]/form[1]/div[1]/div[1]/div[2]/table[3]/tbody[1]/tr[3]/td[2]/span[1]/a[1]"); //List<string> keyWords = new List<string>(); //foreach (HtmlNode keyNode in keyNodes) //{ // keyWords.Add(keyNode.InnerText); //} string bdinclude = doc.GetElementbyId("baidu").InnerText; dt.Rows.Add(y, domain, bdinclude); y++; //修改图标控件 OutDelegate outdelegate = new OutDelegate(OutText); this.Dispatcher.BeginInvoke(outdelegate, new object[] { "xx" }); Thread.Sleep(500); }
public void Go() { for (int i = 0; i < title.Count; i++) { string responsestr = ""; try { ++y; if (method == "POST") { responsestr = PostToUrl.PostDataToUrl(postdata.Replace("{title}", title[i]).Replace("{context}", context), posturl, cc); } else { responsestr = PostToUrl.SendDataByGET(posturl, postdata.Replace("{title}", title[i]).Replace("{context}", context), cc); } } catch (Exception) { Thread.CurrentThread.Abort(); } OutDelegate outdelegate = new OutDelegate(OutText); this.Dispatcher.BeginInvoke(outdelegate, new object[] { responsestr }); Thread.Sleep(delay * 1000); } }
public void OutPut(string message) { if (form.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(OutPut); form.BeginInvoke(outdelegate, new object[] { message }); return; } form.AddLoginMessage(message); }
private void update(object sender, EventArgs e) { //Flow flow = new Flow(); //处理流量的类 ArrayList TcpIP_RawPackages = fm.GetIntervalTcpIP_packages(); OutDelegate outdelegate = new OutDelegate(ShowPackets);//ShowPackets OutText this.BeginInvoke(outdelegate, new object[] { TcpIP_RawPackages }); //flow_label.Text = System.Convert.ToString(flow.lastUp+flow.lastDown); }
public void Debug(string message) { if (form.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(Debug); form.BeginInvoke(outdelegate, new object[] { message }); return; } form.AddDebugMessage(message); }
public void OutFirmwareVersionText(string text) { if (lbFirmwareVersion.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(OutFirmwareVersionText); this.BeginInvoke(outdelegate, new object[] { text }); return; } string[] tmp = text.Split(','); lbFirmwareVersion.Text = Pub.GetResText(formCode, "lbFirmwareVersion", "") + tmp[0]; lbAntennaID.Text = Pub.GetResText(formCode, "lbAntennaID", "") + tmp[1]; }
public void OutText(string text) { if (label.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(OutText); label.BeginInvoke(outdelegate, new object[] { text }); return; } SaveFaceLog(text); }
public static void OutText(bool isend, object dtSource, ComboBox comboBoxUd) { if (comboBoxUd.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(OutText); comboBoxUd.BeginInvoke(outdelegate, new object[] { isend, dtSource, comboBoxUd }); return; } comboBoxUd.DataSource = null; comboBoxUd.DataSource = dtSource; if (comboBoxUd.Items.Count != 0) { comboBoxUd.SelectedIndex = 0; } if (isend) { comboBoxUd.SelectedIndex = comboBoxUd.Items.Count - 1; } }
public void OutText(bool isend, object dtSource) { if (comboBox1.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(OutText); BeginInvoke(outdelegate, new object[] { isend, dtSource }); return; } comboBox1.DataSource = null; comboBox1.DataSource = dtSource; //foreach (UsbDisk item in (UsbDiskCollection)dtSource) //{ // MessageBox.Show(item.ToString()); //} //MessageBox.Show(((UsbDiskCollection)dtSource).ToString ()); if (comboBox1.Items.Count != 0) { comboBox1.SelectedIndex = 0; } if (isend) { comboBox1.SelectedIndex = comboBox1.Items.Count - 1; } }
public void OuttvInfoText(string text) { if (msgGrid.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(OuttvInfoText); this.BeginInvoke(outdelegate, new object[] { text }); return; } try { infoIndex = infoIndex + 1; DataTableReader dr = null; string[] tmp = text.Split(','); if (tmp.Length > 4) { dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_004003, new string[] { "5", tmp[2], tmp[1] })); if (dr.Read()) { dtReal.Rows.Add(new object[] { infoIndex.ToString(), tmp[0], tmp[1], dr["CategoryName"].ToString(), tmp[2], dr["ProductsName"].ToString(), double.Parse(dr["ProductsPrice"].ToString()).ToString("0.00"), tmp[4] }); } else { dtReal.Rows.Add(new object[] { infoIndex.ToString(), tmp[0], tmp[1], " ", tmp[2], " ", tmp[3], tmp[4] }); } } else { dtReal.Rows.Add(new object[] { infoIndex, " ", " ", " ", " ", " ", " ", text }); } Application.DoEvents(); } catch (Exception E) { Pub.ShowErrorMsg(E); } }
public void updateUI() { OutDelegate outdelegate = new OutDelegate(OutText); this.Dispatcher.BeginInvoke(outdelegate, new object[] { "xx" }); }
public void OutText(bool isend, object dtSource) { if (comboBox1.InvokeRequired) { OutDelegate outdelegate = new OutDelegate(OutText); BeginInvoke(outdelegate, new object[] { isend, dtSource }); return; } comboBox1.DataSource = null; comboBox1.DataSource = dtSource; if (comboBox1.Items.Count != 0) { comboBox1.SelectedIndex = 0; } if (isend) { comboBox1.SelectedIndex = comboBox1.Items.Count - 1; } }
public static TResult PassReference <TArg, TResult>(TypedReference tref, OutDelegate <TArg, TResult> del) { return(PassReference <TArg, TResult>(tref, delegate(ref TArg arg) { return del(out arg); })); }
private void getBaiduIndex(string keystr) { string pageUrl = "http://index.baidu.com/?tpl=trend&word=" + Common.UrlEncode(keystr).ToUpper(); WebClient wc = new WebClient(); byte[] pageSourceBytes = wc.DownloadData(new Uri(pageUrl)); //string pageSource = Encoding.GetEncoding("gb2312").GetString(pageSourceBytes); //获取编码 string encode = ""; var r_utf8 = new System.IO.StreamReader(new System.IO.MemoryStream(pageSourceBytes), Encoding.UTF8); var r_gbk = new System.IO.StreamReader(new System.IO.MemoryStream(pageSourceBytes), Encoding.Default); var t_utf8 = r_utf8.ReadToEnd(); var t_gbk = r_gbk.ReadToEnd(); if (!Common.isLuan(t_utf8)) { encode = "utf8"; } else { encode = "gbk"; } //根据编码读取 string pageSource = ""; if (encode == "utf8") { pageSource = Encoding.GetEncoding("utf-8").GetString(pageSourceBytes); } else { pageSource = Encoding.GetEncoding("gb2312").GetString(pageSourceBytes); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageSource); //string index = doc.DocumentNode.SelectSingleNode(indexXPath).InnerText; //string moblie = doc.DocumentNode.SelectSingleNode(moblieXPath).InnerText; //dt1.Rows.Add(keystr, index, moblie); dt1.Rows.Add(keystr, "333", "444"); dt1.Rows.Add(keystr, "444", "111"); dt1.Rows.Add(keystr, "555", "23"); dt1.Rows.Add(keystr, "666", "45"); dt1.Rows.Add(keystr, "777", "21"); //System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(pageUrl); //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"; //System.Net.WebResponse response = request.GetResponse(); //System.IO.Stream resStream = response.GetResponseStream(); //System.IO.StreamReader sr = new System.IO.StreamReader(resStream, Encoding.Default); //string html = (sr.ReadToEnd()); //resStream.Close(); //sr.Close(); //MessageBox.Show(Common.StripHT(html)); ++y; OutDelegate outdelegate = new OutDelegate(OutText); this.Dispatcher.BeginInvoke(outdelegate, new object[] { "xx" }); }
private void Gather(object obj) { keyengine ke = obj as keyengine; string key = ke.key; string engine = ke.engine; StreamReader sr; try { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://www.baidu.com/s?wd=" + key); HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); Stream srtStream = webResponse.GetResponseStream(); sr = new StreamReader(srtStream, Encoding.GetEncoding("utf-8")); } catch { MessageBox.Show("对不起!网络没有连接。"); return; } finally { } String totalLines = sr.ReadToEnd(); //匹配标题 List <string> second = new List <string>(); //---------百度修改了代码:20141009:<div id="rs"><div class="tt">相关搜索</div> .... </table></div> Regex reg = new Regex("<div id=\"rs\">.*?</table></div>"); Match mat = reg.Match(totalLines); //MessageBox.Show(mat.Value); if (mat.Success) { Regex href = new Regex(@"<a\s*[^>]*>([\s\S]+?)</a>", RegexOptions.IgnoreCase); MatchCollection like_key = href.Matches(mat.Value); foreach (Match ma in like_key) { if (dt.Select("key='" + ma.Groups[1].Value + "'").Length == 0) { second.Add("http://www.baidu.com" + Common.MatchURL(ma.Groups[0].Value, "<a href=\"", "\">")); if (includekey == "") { dt.Rows.Add(id++, ma.Groups[1].Value, engine); } else if (MatchRule(ma.Groups[1].Value)) { dt.Rows.Add(id++, ma.Groups[1].Value, engine); } } } } Thread.Sleep(500); if (grade > 1) { SecondGrade(second); } //实时更新进度条 y++; Thread trd = new Thread(new ThreadStart(this.ThreadTask)); trd.IsBackground = true; trd.Start(); //修改图标控件 OutDelegate outdelegate = new OutDelegate(OutText); this.Dispatcher.BeginInvoke(outdelegate, new object[] { "xx" }); }
public static void PassReference <TArg>(TypedReference tref, OutDelegate <TArg> del) { PassReference <TArg>(tref, delegate(ref TArg arg) { del(out arg); }); }
private void Gather(object obj) { IURL iurl = obj as IURL; int i = iurl.i; string url = iurl.url; try { string pageUrl = url; WebClient wc = new WebClient(); byte[] pageSourceBytes = wc.DownloadData(new Uri(pageUrl)); //获取编码 string encode = ""; var r_utf8 = new System.IO.StreamReader(new System.IO.MemoryStream(pageSourceBytes), Encoding.UTF8); //将html放到utf8编码的StreamReader内 var r_gbk = new System.IO.StreamReader(new System.IO.MemoryStream(pageSourceBytes), Encoding.Default); //将html放到gbk编码的StreamReader内 var t_utf8 = r_utf8.ReadToEnd(); //读出html内容 var t_gbk = r_gbk.ReadToEnd(); //读出html内容 if (!isLuan(t_utf8)) //判断utf8是否有乱码 { encode = "utf8"; } else { encode = "gbk"; } //根据编码读取 string pageSource = ""; if (encode == "utf8") { pageSource = Encoding.GetEncoding("utf-8").GetString(pageSourceBytes); } else { pageSource = Encoding.GetEncoding("gb2312").GetString(pageSourceBytes); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pageSource); //获取标题 HtmlNodeCollection keyNodes = doc.DocumentNode.SelectNodes("/html[1]/head[1]/title[1]"); List <string> keyWords = new List <string>(); foreach (HtmlNode keyNode in keyNodes) { dt1.Rows[i][1] = replace(keyNode.InnerText.Trim()).Trim(); } } catch { } finally { //修改图标控件--在线程中修改界面需要使用委托 OutDelegate outdelegate = new OutDelegate(OutText); this.Dispatcher.BeginInvoke(outdelegate, new object[] { "xx" }); ++y; //实时更新界面元素 Thread trd = new Thread(new ThreadStart(this.ThreadTask)); trd.IsBackground = true; trd.Start(); } }