c# 获取本机登录的所有qq号码!

软件运行界面:

c# 获取本机登录的所有qq号码!_第1张图片

直接上完整代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace getPC_qq
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }

        WebClient wb = new WebClient();

        /// 
        /// Web控件对应的Navigating事件
        /// 
        /// 
        /// 
        private void M_web_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            string url = e.Url.ToString();
        }
        /// 
        /// 一个全局Web控件对象
        /// 
        private WebBrowser M_web;
        private void button1_Click(object sender, EventArgs e)
        {
            //Thread th = new Thread(new ThreadStart(() =>
            //{

            WebBrowser M_web1 = new WebBrowser();
            if (M_web == null)
            {
                //初始化一下Web控件(肉眼看不到的哦)
                M_web = new System.Windows.Forms.WebBrowser();
                M_web.ScriptErrorsSuppressed = true;
                M_web.Navigating += new WebBrowserNavigatingEventHandler(M_web_Navigating);
            }
            //Web控件载入页面(这个页面就是我们用来获取QQ号的页面)
            M_web.Navigate("http://ui.ptlogin2.qq.com/cgi-bin/login?hide_title_bar=0&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=636014201&target=self&s_url=http%3A//www.qq.com/qq2012/loginSuccess.htm");
            M_web.ScriptErrorsSuppressed = true;

            while (M_web.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
            if (M_web.ReadyState == WebBrowserReadyState.Complete)
            {
                HtmlElement target = M_web.Document.GetElementById("qlogin_list");

                if (target != null)
                {
                    target.AttachEventHandler("onpropertychange", handler);
                }
            }
            //}));
            //th.IsBackground = true;
            //th.Start();
            #region
            //wb.Encoding = Encoding.UTF8;
            //string res = wb.DownloadString("http://ui.ptlogin2.qq.com/cgi-bin/login?hide_title_bar=0&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=636014201&target=self&s_url=http%3A//www.qq.com/qq2012/loginSuccess.htm");
            //richTextBox1.Text = res;
            #endregion


        }

        private void handler(Object sender, EventArgs e)
        {
            HtmlElement div = M_web.Document.GetElementById("qlogin_list");
            if (div == null) return;
            String contentLoaded = div.InnerHtml; // get the content loaded via ajax

            List QQNumberList = new List();
            HtmlElementCollection htmlElementCollection = div.All;
            foreach (HtmlElement currentElement in htmlElementCollection)//在集合中遍历所有元素来寻找
            {
                string curstr = currentElement.OuterHtml;
                if (curstr != null)
                {
                    string idstr = currentElement.GetAttribute("id");
                    if (idstr.Contains("img_"))
                    {
                        if (curstr.ToLower().Contains("
        /// 获取字符串指定头和尾之间的内容
        /// 
        /// 起始字符串
        /// 结束字符串
        /// 主串
        /// 
        private string Match_Str(string startChar, string endChar, string str)
        {
            try
            {
                Regex reg = new Regex("(?<=" + startChar + ").*?(?=" + endChar + ")", RegexOptions.IgnoreCase);
                Match m = reg.Match(str);
                if (m.Success)
                {
                    return m.ToString();
                }
            }
            catch (System.Exception ex)
            {

            }
            return "";
        }

        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
        }
    }
}

 

你可能感兴趣的:(工具软件)