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.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;
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
好了,希望大家不要见笑,一个初学者的弱弱创作...