C# 自動投票和手機號碼歸屬地查詢 - 簡單程序源碼分享(高手飄過)
如有轉載,請注明出處: http://www.cnblogs.com/sabby/archive/2012/01/01/2309675.html
C# 自動投票和手機號碼歸屬地查詢 - 簡單程序源碼分享(高手飄過)
一、自動投票
網上最近出現很多投票支持,今天在網上看到突發奇想要寫一個簡單程序自己刷,同時分享個手機號碼歸屬地查詢源程序代碼,希望大家支持下小女的博客的第一個作品。
1.用Chrome打開 你想投票的網頁,這里我以 http://ent.ifeng.com/tv/special/2012kuanian/ 為例,打開后按F12就可以下面網頁的信息,如圖:
點擊網頁上“我支持他”
點進去..
找到它請求的地址並打開像這樣:
接下來開始寫程序,代碼如下:
using System;
using System.Windows.Forms;
namespace HnVote
{
public partial class Form1 : Form
{
private static int _count;
public Form1()
{
InitializeComponent();
Timer timer = new Timer {Interval = 1000};
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
private void timer_Tick( object sender, EventArgs e)
{
Text = " 正在刷第 " + _count++ + " 票... ";
webBrowser1.Url = new Uri( " http://survey.news.ifeng.com/accumulator_ext.php?key=http%3A%2F%2Fent.ifeng.com%2Ftv%2Fspecial%2F2012kuanian%2F%3F6%3Ft%3Dding&format=js&callback=ifeng_Ding_Handler.InitDingNum&extdata=ding_num_box6 ");
}
}
}
using System.Windows.Forms;
namespace HnVote
{
public partial class Form1 : Form
{
private static int _count;
public Form1()
{
InitializeComponent();
Timer timer = new Timer {Interval = 1000};
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
private void timer_Tick( object sender, EventArgs e)
{
Text = " 正在刷第 " + _count++ + " 票... ";
webBrowser1.Url = new Uri( " http://survey.news.ifeng.com/accumulator_ext.php?key=http%3A%2F%2Fent.ifeng.com%2Ftv%2Fspecial%2F2012kuanian%2F%3F6%3Ft%3Dding&format=js&callback=ifeng_Ding_Handler.InitDingNum&extdata=ding_num_box6 ");
}
}
}
運行下:
二、 手機號碼查詢
它會自動不挺刷這個網頁,看到這你們都懂了吧,下面再說說手機號碼查詢,這個跟刷票一樣原理,前幾部都要一樣,同樣用瀏覽器打開手機號碼查詢的網站,同以上步驟找到他調用的地址,最后編寫代碼如下:
using System;
using System.Windows.Forms;
using System.Xml;
namespace HnVote
{
public partial class Mobile : Form
{
public Mobile()
{
InitializeComponent();
}
private static string[] GetMobileInfo( string number)
{
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load( " http://api.showji.com/Locating/default.aspx?m= " + number);
XmlNamespaceManager cx = new XmlNamespaceManager(xmlDocument.NameTable);
cx.AddNamespace( " content ", " http://api.showji.com/Locating/ ");
XmlNodeList nodes = xmlDocument.SelectNodes( " //content:QueryResult|//content:Mobile|//content:Province|//content:City|//content:Corp|//content:Card|//content:AreaCode|//content:PostCode ", cx);
if (nodes.Count == 8)
{
if ( " True ".Equals(nodes[ 1].InnerText))
{
return new string[]
{
nodes[ 0].InnerText, nodes[ 2].InnerText, nodes[ 3].InnerText, nodes[ 4].InnerText,
nodes[ 5].InnerText, nodes[ 6].InnerText + nodes[ 7].InnerText
};
}
}
return new string[] { " false " };
}
catch (Exception)
{
return new string[] { " false " };
}
}
private void button1_Click( object sender, EventArgs e)
{
try
{
string[] num = GetMobileInfo(textBox1.Text);
MessageBox.Show( " 所查號碼: " + num[ 0] + " \n歸屬省份: " + num[ 1] + " \n歸屬城市: " + num[ 2] + " \n城市區號: " + num[ 3] + " \n城市郵編: " +
num[ 4] + " \n卡 類 型: " + num[ 5], " 查詢結果 ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, " 錯誤提示 ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void textBox1_KeyDown( object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
button1_Click(sender,e);
}
}
}
using System.Windows.Forms;
using System.Xml;
namespace HnVote
{
public partial class Mobile : Form
{
public Mobile()
{
InitializeComponent();
}
private static string[] GetMobileInfo( string number)
{
try
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load( " http://api.showji.com/Locating/default.aspx?m= " + number);
XmlNamespaceManager cx = new XmlNamespaceManager(xmlDocument.NameTable);
cx.AddNamespace( " content ", " http://api.showji.com/Locating/ ");
XmlNodeList nodes = xmlDocument.SelectNodes( " //content:QueryResult|//content:Mobile|//content:Province|//content:City|//content:Corp|//content:Card|//content:AreaCode|//content:PostCode ", cx);
if (nodes.Count == 8)
{
if ( " True ".Equals(nodes[ 1].InnerText))
{
return new string[]
{
nodes[ 0].InnerText, nodes[ 2].InnerText, nodes[ 3].InnerText, nodes[ 4].InnerText,
nodes[ 5].InnerText, nodes[ 6].InnerText + nodes[ 7].InnerText
};
}
}
return new string[] { " false " };
}
catch (Exception)
{
return new string[] { " false " };
}
}
private void button1_Click( object sender, EventArgs e)
{
try
{
string[] num = GetMobileInfo(textBox1.Text);
MessageBox.Show( " 所查號碼: " + num[ 0] + " \n歸屬省份: " + num[ 1] + " \n歸屬城市: " + num[ 2] + " \n城市區號: " + num[ 3] + " \n城市郵編: " +
num[ 4] + " \n卡 類 型: " + num[ 5], " 查詢結果 ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, " 錯誤提示 ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void textBox1_KeyDown( object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
button1_Click(sender,e);
}
}
}
}
界面:
下面我提供源程序個大家下載,源碼下載:http://www.ctdisk.com/file/3966695
好了,希望大家不要見笑,一個初學者的弱弱創作...