基本信息
源码名称:c# 模拟点击网页(可清空缓存、清空cookie等)网络抓取
源码大小:1.24M
文件格式:.rar
开发语言:C#
更新时间:2017-06-08
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;
using mshtml;
using System.Net;
using System.Runtime.InteropServices;

namespace WebClick_Tool
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            //RegSetting.RegeditKeyDel("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\5.0\\User Agent", new List<string>() {"ddd","默认" });
            DisMes = new MsgLableTxt(LbMes);//建立委托
            Enb = new EnbBt(Ebbt);
            Bclick = new BtClick(button2_Click);
            FormMian = this;
            KeyPress_o.Hook_Start();
            timer1.Start();
        }
        /// <summary>
        /// 停止
        /// </summary>
        public static bool StopAll = false;
        /// <summary>
        /// 窗体对象
        /// </summary>
        public static Form FormMian = null;
        /// <summary>
        /// 浏览器配置
        /// </summary>
        List<string> BroswerConfig = new List<string>();
        /// <summary>
        /// 关键词列表
        /// </summary>
        List<string> GjcList = new List<string>();
        /// <summary>
        /// 浏览器环境
        /// </summary>
        List<List<string>> BrowserEnvironment = new List<List<string>>();
        /// <summary>
        /// 代理缓存
        /// </summary>
        public static List<string> ProxyList = new List<string>();
        public static List<string> ProxyList_Old = new List<string>();
        /// <summary>
        /// 使用旧还是新
        /// </summary>
        public static bool NowRead = false;
        /// <summary>
        /// 声明委托类
        /// </summary>
        /// <param name="MsgStr"></param>
        public delegate void MsgLableTxt(string MsgStr);
        /// <summary>
        /// 定义委托
        /// </summary>
        public static MsgLableTxt DisMes;
        /// <summary>
        /// 声明委托类
        /// </summary>
        /// <param name="MsgStr"></param>
        public delegate void EnbBt();
        /// <summary>
        /// 定义委托
        /// </summary>
        public static EnbBt Enb;
        /// <summary>
        /// 声明委托类
        /// </summary>
        /// <param name="MsgStr"></param>
        public delegate void BtClick(object sender, EventArgs e);
        /// <summary>
        /// 定义委托
        /// </summary>
        public static BtClick Bclick;

        ThreadWork Tw;


        private void LbMes(string Msg)
        {
            if (label1.InvokeRequired)
            {
                this.Invoke(DisMes, Msg);
            }
            else
                label1.Text = Msg;
        }

        private void Ebbt()
        {
            if (button1.InvokeRequired)
            {
                this.Invoke(Enb);
            }
            else
                button1.Enabled = true;
            if (button2.InvokeRequired)
            {
                this.Invoke(Enb);
            }
            else
                button2.Enabled = true;
        }

        /// <summary>
        /// 加载配置
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            StreamReader Sr = new StreamReader(Application.StartupPath   "\\Config.txt",Encoding.Default);
            BroswerConfig.AddRange(Sr.ReadToEnd().Replace("\r\n", "^").Split('^'));
            Sr = new StreamReader(Application.StartupPath   "\\待点击关键词.txt", Encoding.Default);
            GjcList.AddRange(Sr.ReadToEnd().Replace("\r\n", "^").Split('^'));

            Sr = new StreamReader(Application.StartupPath   "\\BrowserEnvironment.txt", Encoding.Default);
            string line = "";
            string[] Lines=null;
            while ((line = Sr.ReadLine()) != null)
            {
                if (line.Contains("Mozilla/") && line.Contains("Windows NT"))
                {
                    line = line.Replace(")", ";");
                    line = line.Replace("(", ";");
                    Lines=line.Split(';');
                    if (Lines.Length > 2)
                    {
                        BrowserEnvironment.Add(new List<string>() { });
                        int TempInt = BrowserEnvironment.Count - 1;
                        for (int i = 0; i < Lines.Length - 1; i  )
                        {
                            BrowserEnvironment[TempInt].Add(Lines[i].Trim());
                        }
                    }
                }
            }
            Sr.Close();
            if (BroswerConfig.Count > 4)
            {
                label1.Text = "加载浏览器设置完成...";
            }
        }
        /// <summary>
        /// 开始点击
        /// </summary>
        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            try
            {
                SetPenetrate();
                StopAll = false;
                Tw = new ThreadWork(BroswerConfig, BrowserEnvironment, GjcList);
                button1.Enabled = false;
                button2.Enabled = false;
                Tw.Work_Thread.Start();
                Tw.out_Work_Thread.Start();
            }
            catch { MessageBox.Show("配置错误!"); }
        }

        /// <summary>
        /// 更新代理
        /// </summary>
        /// <returns></returns>
        public static bool GetProxy()
        {
            try
            {
                string IpStr = GetPage("http://jipin.aliapp.com/ip.txt", "", Encoding.UTF8);
                if (IpStr.Replace("\r\n", "").Trim() != "" && IpStr.Contains("\r\n"))
                {
                    ProxyList_Old.Clear();
                    if (ProxyList.Count != 0)
                    {
                        ProxyList_Old = ProxyList.GetRange(0, ProxyList.Count);
                    }
                    NowRead = true;
                    ProxyList.Clear();
                    ProxyList.AddRange(IpStr.Replace("\r\n", "*").Split('*'));
                    NowRead = false;
                }
                else
                {
                    return false;
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 获取源代码
        /// </summary>
        /// <param name="url"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public static string GetPage(string url, string PointStr, Encoding Ec)
        {
            HttpWebRequest request = null;
            HttpWebResponse response = null;
            StreamReader reader = null;
            try
            {
                request = (HttpWebRequest)WebRequest.Create(url);
                request.AllowAutoRedirect = true;
                request.AllowWriteStreamBuffering = true;
                if (PointStr != "")
                {
                    //设置代理
                    WebProxy proxy = new WebProxy();
                    proxy.Address = new Uri("http://"   PointStr);
                    request.UseDefaultCredentials = true;
                    request.Proxy = proxy;
                }
                request.Timeout = 10000;
                response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.OK &&
                   response.ContentLength < 1024 * 1024)
                {
                    reader = new StreamReader(response.GetResponseStream(), Ec);
                    string html = reader.ReadToEnd();
                    return html;
                }
            }
            catch
            {
                return "";
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                    response = null;
                }
                if (reader != null)
                    reader.Close();
                if (request != null)
                    request = null;
            }
            return "";
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Size.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Size.Height - this.Height);
        }
        int time = 5000;
        bool gj = false;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (StopAll)
            {
                label1.Text = "停止...";
                timer1.Stop();
            }
            if (!gj)
                label1.Text = (time / 1000.0).ToString("0.00")   "秒后自动加载配置!  F2停止...";
            else
                label1.Text = (time / 1000.0).ToString("0.00")   "秒后自动开始!  F2停止...";
            time -= 100;
            if (time <= 0 && !gj)
            {
                gj = true;
                button1_Click(null, null);
                timer1.Start();
                time = 5000;
            }
            if (time <= 0 && gj)
            {
                timer1.Stop();
                button2_Click(null, null);
            }
        }

        #region 窗体鼠标穿透
        private const uint WS_EX_LAYERED = 0x80000;
        private const int WS_EX_TRANSPARENT = 0x20;
        private const int GWL_STYLE = (-16);
        private const int GWL_EXSTYLE = (-20);
        private const int LWA_ALPHA = 0;

        [DllImport("user32", EntryPoint = "SetWindowLong")]
        private static extern uint SetWindowLong(
        IntPtr hwnd,
        int nIndex,
        uint dwNewLong
        );

        [DllImport("user32", EntryPoint = "GetWindowLong")]
        private static extern uint GetWindowLong(
        IntPtr hwnd,
        int nIndex
        );

        [DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
        private static extern int SetLayeredWindowAttributes(
        IntPtr hwnd,
        int crKey,
        int bAlpha,
        int dwFlags
        );

        /// <summary> 
        /// 设置窗体具有鼠标穿透效果 
        /// </summary> 
        public void SetPenetrate()
        {
            this.TopMost = true;
            GetWindowLong(this.Handle, GWL_EXSTYLE);
            SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
            SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
        }
        #endregion
    }
}