一 功能需求
1.自动随机点击数据库中网页地址,可设定时间间隔。
2.可按指定时间段内的随机时间点击网页。(暂为实现)
3.可设定完成后自动退出程序。
4.可设置代理。
5.加入热键显示和隐藏功能。
6.按规则抓取网页中的链接。
7.定时点击网页中的按钮。
二 目前实现情况
1.自动点击数据库中的网页,指定时间间隔可设置代理,加入热键显示和隐藏功能,按规则抓取网页中的链接。没有实现随机性。
三 可设置代理上网
四 仅供学习交流之用,勿用它途
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Collections;
namespace WindowsApplication1
{
public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
};
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
RegisterHotKey(Handle, 100, 2, Keys.Left); // 热键一:Control +光标左箭头
RegisterHotKey(Handle, 200, 2, Keys.Right); //热键一:Control +光标右箭头
RegisterHotKey(Handle, 300, 2, Keys.Up); // 热键一:Control +光标上箭头
RegisterHotKey(Handle, 400, 2, Keys.Down); // 热键一:Control +光标下箭头
}
int i = 0;
/// <summary>
/// ///////////////////////////////////////////////////////////////////////////////
[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
private void RefreshIESettings(string strProxy)
{
const int INTERNET_OPTION_PROXY = 38;
const int INTERNET_OPEN_TYPE_PROXY = 3;
Struct_INTERNET_PROXY_INFO struct_IPI;
// Filling in structure
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
// Allocating memory
IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
// Converting structure to IntPtr
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}
private void NativeUrl(string URL)
{
//System.Object nullObject = 0;
//string strTemp = String.Empty;
//System.Object nullObjStr = strTemp;
webBrowser1.Navigate(URL);
}
///////////////////////////////////////////////////////////////////////////////////
#region 实现热键
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool RegisterHotKey(
IntPtr hWnd, // handle to window
int id, // hot key identifier
uint fsModifiers, // key-modifier options
Keys vk // virtual-key code
);
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool UnregisterHotKey(
IntPtr hWnd, // handle to window
int id // hot key identifier
);
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
protected override void WndProc(ref Message m)//监视Windows消息
{
const int WM_HOTKEY = 0x0312; //如果m.Msg的值为0x0312那么表示用户按下了热键
switch (m.Msg)
{
case WM_HOTKEY:
ProcessHotkey(m); //按下热键时调用ProcessHotkey()函数
break;
}
base.WndProc(ref m); //将系统消息传递自父类的WndProc
}
private void ProcessHotkey(Message m)
{
IntPtr id = m.WParam; //IntPtr用于表示指针或句柄的平台特定类型
//MessageBox.Show(id.ToString());
string sid = id.ToString();
switch (sid)
{
case "100": ; break; // 按下Control +光标左箭头,调用函数DecreseVolumnb();
case "200":; break; // 按下Control +光标右箭头,调用函数AddVolumnb()
case "300":// 按下Control +光标上箭头,显示窗体
this.Visible = true;
break;
case "400":// 按下Control +光标下箭头,隐藏窗体
this.Visible = false;
break;
}
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
UnregisterHotKey(Handle, 100); //卸载第1个快捷键
UnregisterHotKey(Handle, 200); //缷载第2个快捷键
UnregisterHotKey(Handle, 300); //卸载第3个快捷键
UnregisterHotKey(Handle, 400); //缷载第4个快捷键
}
#endregion
int start=0;
int count = 0;
private void Form2_Load(object sender, EventArgs e)
{
try
{
// TODO: 这行代码将数据加载到表“dataDataSet.biao1”中。您可以根据需要移动或移除它。
this.biao1TableAdapter.Fill(this.dataDataSet.biao1);
button2.Enabled = false;
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message,"错误!");
}
}
private void button1_Click(object sender, EventArgs e) //start
{
if (chk_IsProxy.Checked == true)
{
RefreshIESettings("192.168.0.1:808"); //使用代理
}
i = 0;
//webBrowser1.Navigate(strUrl);
count = dataDataSet.biao1.Rows.Count;
progressBar1.Maximum = start + count;
progressBar1.Minimum = 0;
progressBar1.Step = 10;
decimal inter = decimal.Parse((textBox1.Text.Trim()));//間隔時間
timer1.Interval = (int)(inter * 1000);
timer1.Start();
button1.Enabled = false;
button2.Enabled = true;
}
private void button3_Click(object sender, EventArgs e) //生成
{
//// string strUrl = dataDataSet.biao1.Rows[0][1].ToString();
// i = 0;
// //webBrowser1.Navigate(strUrl);
// int inter = int.Parse(textBox1.Text.Trim());
// timer1.Interval = inter*1000;
// timer1.Start();
count = int.Parse(textBox2.Text.Trim());
start = int.Parse(textBox3.Text.Trim());
progressBar1.Maximum = count;
progressBar1.Minimum = 0;
progressBar1.Step = 10;
for (int i = 0; i < count; i++) //2000
{
StringBuilder sb = new StringBuilder();
sb.Append("http://www.docin.com/u-" + (start + i).ToString() + ".html");//start 250000
biao1BindingSource.AddNew();
biao1BindingSource.EndEdit();
dataGridView1.Rows[i].Cells[1].Value = sb.ToString();
progressBar1.Value = i;
}
MessageBox.Show("生产网址完成","提示!",MessageBoxButtons.OK,MessageBoxIcon.Information);
///////////////////////////////////////////////////////////
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (webBrowser1.IsBusy == true) //如果忙停止处理
{
webBrowser1.Stop();
}
string strUrl = dataDataSet.biao1.Rows[i][1].ToString();
dataGridView1.Rows[i].Selected = true;
//RefreshIESettings("192.168.0.1:808"); //使用代理
NativeUrl(strUrl);
i++;
if (i >= count)
{
timer1.Stop();
button1.Enabled = true;
MessageBox.Show("点击完成", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (checkBox1.Checked == true)
{
this.Close();
}
}
progressBar1.Value = i;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"错误!",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, EventArgs e) //stop
{
timer1.Stop();
button1.Enabled = true;
}
private void button4_Click(object sender, EventArgs e) //save
{
try
{
this.biao1BindingSource.EndEdit();
this.biao1TableAdapter.Update(this.dataDataSet.biao1);
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message,"错误!");
}
}
private void button5_Click(object sender, EventArgs e) //Refresh
{
this.biao1TableAdapter.Fill(this.dataDataSet.biao1);
}
private void button6_Click(object sender, EventArgs e)
{
dataDataSet.biao1.Clear();
//IHTMLDOCTMNET
}
private void button7_Click(object sender, EventArgs e)
{
try
{
string pre = textBox4.Text.Trim();
string all_code = webBrowser1.Document.Body.OuterHtml;
string p = pre + @"([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
ArrayList my_list = new ArrayList();
Regex re = new Regex(p, RegexOptions.IgnoreCase);
MatchCollection mc = re.Matches(all_code);
int j = 0;
for (int i = 0; i <= mc.Count - 1; i++)
{
//bool _foo = false;
string name = mc[i].ToString();
//foreach (string list in my_list)
//{
// if (name == list)
// {
// _foo = true;
// break;
// }
//}//过滤
biao1BindingSource.AddNew();
biao1BindingSource.EndEdit();
dataGridView1.Rows[i].Cells[1].Value = "http://www.docin.com" + name;
if(i%2 == 0)
{
//biao1BindingSource.AddNew();
//biao1BindingSource.EndEdit();
//dataGridView1.Rows[j].Cells[1].Value = "http://www.docin.com"+name;
j++;
}
//if (!_foo)
//{
//}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"提示!");
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Collections;
namespace WindowsApplication1
{
public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
};
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
RegisterHotKey(Handle, 100, 2, Keys.Left); // 热键一:Control +光标左箭头
RegisterHotKey(Handle, 200, 2, Keys.Right); //热键一:Control +光标右箭头
RegisterHotKey(Handle, 300, 2, Keys.Up); // 热键一:Control +光标上箭头
RegisterHotKey(Handle, 400, 2, Keys.Down); // 热键一:Control +光标下箭头
}
int i = 0;
/// <summary>
/// ///////////////////////////////////////////////////////////////////////////////
[DllImport("wininet.dll", SetLastError = true)]
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
private void RefreshIESettings(string strProxy)
{
const int INTERNET_OPTION_PROXY = 38;
const int INTERNET_OPEN_TYPE_PROXY = 3;
Struct_INTERNET_PROXY_INFO struct_IPI;
// Filling in structure
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
// Allocating memory
IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
// Converting structure to IntPtr
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
}
private void NativeUrl(string URL)
{
//System.Object nullObject = 0;
//string strTemp = String.Empty;
//System.Object nullObjStr = strTemp;
webBrowser1.Navigate(URL);
}
///////////////////////////////////////////////////////////////////////////////////
#region 实现热键
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool RegisterHotKey(
IntPtr hWnd, // handle to window
int id, // hot key identifier
uint fsModifiers, // key-modifier options
Keys vk // virtual-key code
);
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数
public static extern bool UnregisterHotKey(
IntPtr hWnd, // handle to window
int id // hot key identifier
);
public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
protected override void WndProc(ref Message m)//监视Windows消息
{
const int WM_HOTKEY = 0x0312; //如果m.Msg的值为0x0312那么表示用户按下了热键
switch (m.Msg)
{
case WM_HOTKEY:
ProcessHotkey(m); //按下热键时调用ProcessHotkey()函数
break;
}
base.WndProc(ref m); //将系统消息传递自父类的WndProc
}
private void ProcessHotkey(Message m)
{
IntPtr id = m.WParam; //IntPtr用于表示指针或句柄的平台特定类型
//MessageBox.Show(id.ToString());
string sid = id.ToString();
switch (sid)
{
case "100": ; break; // 按下Control +光标左箭头,调用函数DecreseVolumnb();
case "200":; break; // 按下Control +光标右箭头,调用函数AddVolumnb()
case "300":// 按下Control +光标上箭头,显示窗体
this.Visible = true;
break;
case "400":// 按下Control +光标下箭头,隐藏窗体
this.Visible = false;
break;
}
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
UnregisterHotKey(Handle, 100); //卸载第1个快捷键
UnregisterHotKey(Handle, 200); //缷载第2个快捷键
UnregisterHotKey(Handle, 300); //卸载第3个快捷键
UnregisterHotKey(Handle, 400); //缷载第4个快捷键
}
#endregion
int start=0;
int count = 0;
private void Form2_Load(object sender, EventArgs e)
{
try
{
// TODO: 这行代码将数据加载到表“dataDataSet.biao1”中。您可以根据需要移动或移除它。
this.biao1TableAdapter.Fill(this.dataDataSet.biao1);
button2.Enabled = false;
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message,"错误!");
}
}
private void button1_Click(object sender, EventArgs e) //start
{
if (chk_IsProxy.Checked == true)
{
RefreshIESettings("192.168.0.1:808"); //使用代理
}
i = 0;
//webBrowser1.Navigate(strUrl);
count = dataDataSet.biao1.Rows.Count;
progressBar1.Maximum = start + count;
progressBar1.Minimum = 0;
progressBar1.Step = 10;
decimal inter = decimal.Parse((textBox1.Text.Trim()));//間隔時間
timer1.Interval = (int)(inter * 1000);
timer1.Start();
button1.Enabled = false;
button2.Enabled = true;
}
private void button3_Click(object sender, EventArgs e) //生成
{
//// string strUrl = dataDataSet.biao1.Rows[0][1].ToString();
// i = 0;
// //webBrowser1.Navigate(strUrl);
// int inter = int.Parse(textBox1.Text.Trim());
// timer1.Interval = inter*1000;
// timer1.Start();
count = int.Parse(textBox2.Text.Trim());
start = int.Parse(textBox3.Text.Trim());
progressBar1.Maximum = count;
progressBar1.Minimum = 0;
progressBar1.Step = 10;
for (int i = 0; i < count; i++) //2000
{
StringBuilder sb = new StringBuilder();
sb.Append("http://www.docin.com/u-" + (start + i).ToString() + ".html");//start 250000
biao1BindingSource.AddNew();
biao1BindingSource.EndEdit();
dataGridView1.Rows[i].Cells[1].Value = sb.ToString();
progressBar1.Value = i;
}
MessageBox.Show("生产网址完成","提示!",MessageBoxButtons.OK,MessageBoxIcon.Information);
///////////////////////////////////////////////////////////
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
if (webBrowser1.IsBusy == true) //如果忙停止处理
{
webBrowser1.Stop();
}
string strUrl = dataDataSet.biao1.Rows[i][1].ToString();
dataGridView1.Rows[i].Selected = true;
//RefreshIESettings("192.168.0.1:808"); //使用代理
NativeUrl(strUrl);
i++;
if (i >= count)
{
timer1.Stop();
button1.Enabled = true;
MessageBox.Show("点击完成", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (checkBox1.Checked == true)
{
this.Close();
}
}
progressBar1.Value = i;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"错误!",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, EventArgs e) //stop
{
timer1.Stop();
button1.Enabled = true;
}
private void button4_Click(object sender, EventArgs e) //save
{
try
{
this.biao1BindingSource.EndEdit();
this.biao1TableAdapter.Update(this.dataDataSet.biao1);
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message,"错误!");
}
}
private void button5_Click(object sender, EventArgs e) //Refresh
{
this.biao1TableAdapter.Fill(this.dataDataSet.biao1);
}
private void button6_Click(object sender, EventArgs e)
{
dataDataSet.biao1.Clear();
//IHTMLDOCTMNET
}
private void button7_Click(object sender, EventArgs e)
{
try
{
string pre = textBox4.Text.Trim();
string all_code = webBrowser1.Document.Body.OuterHtml;
string p = pre + @"([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
ArrayList my_list = new ArrayList();
Regex re = new Regex(p, RegexOptions.IgnoreCase);
MatchCollection mc = re.Matches(all_code);
int j = 0;
for (int i = 0; i <= mc.Count - 1; i++)
{
//bool _foo = false;
string name = mc[i].ToString();
//foreach (string list in my_list)
//{
// if (name == list)
// {
// _foo = true;
// break;
// }
//}//过滤
biao1BindingSource.AddNew();
biao1BindingSource.EndEdit();
dataGridView1.Rows[i].Cells[1].Value = "http://www.docin.com" + name;
if(i%2 == 0)
{
//biao1BindingSource.AddNew();
//biao1BindingSource.EndEdit();
//dataGridView1.Rows[j].Cells[1].Value = "http://www.docin.com"+name;
j++;
}
//if (!_foo)
//{
//}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"提示!");
}
}
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/