请教如何用C#自动实现如下操作 比如http://www.sz800.com/sfz,这个网站,手工的操作方法为在身份证号码后面输入,之后点击快速查询,然后得出结果,但由于我手头有好几万个身份证要验证,想用程序来实现,请问:如何用C#模拟这一过程,请高手帮帮忙,小弟这两天要向领导交差,不然就惨了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用webbrowser控件访问http://www.sz800.com/sfz/index.asp?xian=身份证号码分析网页 *****************************************************************************欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/ webrequest请求url得到页面数据,提取你要的信息 这种机械式操作.你可以考虑使用按键精灵来帮你做.把要查的身份证放在一个EXCEL里,然后用按键精灵来做你重复执行... :-)这样更快. 请feiyun0112兄说清楚点,行不?我真的是不懂 //分析了一下网页的格式, //下面 //提供一个思路,如果要查询几万条的话,速度肯定不行 //我这里每次调用大概需要2秒钟 //需要调用 WebClient.DownloadStringAsync 这个异步方法, //在回调方法中进行处理 string careID = "320725197905231232"; //查询的号码 System.Net.WebClient client = new System.Net.WebClient(); client.Encoding = System.Text.Encoding.Default; string reply = client.DownloadString( "http://www.sz800.com/sfz/index.asp?xian=" + careID ); string city = string.Empty; //原户籍地: string birthday = string.Empty; //出生年月: string sex = string.Empty; //性 别: string msg = string.Empty; //提示: int iBegin = -1; //开始位置 int iEnd = -1; //结束位置 iBegin = reply.IndexOf( "查询号码:" ); if ( iBegin == -1 ) { //没查到信息, //可以在循环中继续查询下一个号码 return; } reply = reply.Substring( iBegin ); //取从 查询号码:开始到最后的内容 //原户籍地 iBegin = reply.IndexOf( "原户籍地:" ); iEnd = reply.IndexOf( "<br></td></tr>", iBegin ); city = reply.Substring( iBegin, iEnd - iBegin ); //出生年月: iBegin = reply.IndexOf( "出生年月:" ); iEnd = reply.IndexOf( "<br></td></tr>", iBegin ); birthday = reply.Substring( iBegin, iEnd - iBegin ); //性别: iBegin = reply.IndexOf( "性 别:" ); iEnd = reply.IndexOf( "</td></tr>", iBegin ); sex = reply.Substring( iBegin, iEnd - iBegin ).Replace( " ", "" ); //提示信息 iBegin = reply.IndexOf( "提示:" ); iEnd = reply.IndexOf( "</td>", iBegin ); msg = reply.Substring( iBegin, iEnd - iBegin ); MessageBox.Show( string.Format( "查询号码:{0}\n{1}\n{2}\n{3}\n{4}", careID, city, birthday, sex, msg ) ); 完善一下 //分析了一下网页的格式, //下面 //提供一个思路,如果要查询几万条的话,速度肯定不行 //我这里每次调用大概需要2秒钟 //需要调用 WebClient.DownloadStringAsync 这个异步方法, //在回调方法中进行处理 string careID = "320621197905231235"; //查询的号码 System.Net.WebClient client = new System.Net.WebClient(); client.Encoding = System.Text.Encoding.Default; string reply = client.DownloadString( "http://www.sz800.com/sfz/index.asp?xian=" + careID ); string city = string.Empty; //原户籍地: string birthday = string.Empty; //出生年月: string sex = string.Empty; //性 别: string msg = string.Empty; //提示: int iBegin = -1; //开始位置 int iEnd = -1; //结束位置 iBegin = reply.IndexOf( "查询号码:" ); if ( iBegin == -1 ) { //没查到信息, //可以在循环中继续查询下一个号码 return; } reply = reply.Substring( iBegin ); //取从 查询号码:开始到最后的内容 //原户籍地 iBegin = reply.IndexOf( "原户籍地:" ); iEnd = reply.IndexOf( "<br></td></tr>", iBegin ); city = reply.Substring( iBegin, iEnd - iBegin ); //出生年月: iBegin = reply.IndexOf( "出生年月:" ); iEnd = reply.IndexOf( "<br></td></tr>", iBegin ); birthday = reply.Substring( iBegin, iEnd - iBegin ); //性别: iBegin = reply.IndexOf( "性 别:" ); iEnd = reply.IndexOf( "</td></tr>", iBegin ); sex = reply.Substring( iBegin, iEnd - iBegin ).Replace( " ", "" ); //提示信息,有两种,一种是提示,说明号码有问题的 //一种是“结果”,说明正确的 iBegin = reply.IndexOf( "提示:" ); if ( iBegin != -1 ) { iEnd = reply.IndexOf( "</td>", iBegin ); msg = reply.Substring( iBegin, iEnd - iBegin ); } else { iBegin = reply.IndexOf( "结果:" ); iEnd = reply.IndexOf( "</td>", iBegin ); msg = reply.Substring( iBegin, iEnd - iBegin ); } MessageBox.Show( string.Format( "查询号码:{0}\n{1}\n{2}\n{3}\n{4}", careID, city, birthday, sex, msg ) ); 我还是不懂,你们是如何得出网址后面的index.asp?xian=身份证号码 可以分析网页的源文件。获取这一段:<form action="index.asp" name=form1 method=post> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="37%" height="30" valign="middle" align=center>身份证号码: <input name=xian size=18 type=text> <input name=submit type=submit value="快速查询"></td> </tr> </table></form>如何你可以做这样一个含下面内容的框架:<form action="http://www.sz800.com/sfz/index.asp" name=form1 method=post> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="37%" height="30" valign="middle" align=center>身份证号码: <input name=xian size=18 type=text> <input name=submit type=submit value="快速查询"></td> </tr> </table></form>再做数据处理,应该可以的,你试试看。 你要分析那个网页的源码的,要知道ASP网页数据提交的几种方法 为什么WPF工程选择了ICO文件图标后,编译出来的exe程序,依然没有ICO效果? 请教,datagridview 判断会员生日 代码托管是什么意思? 加密狗? Assembly.GetTypes() 与 typeof() 不相等。。高手请进。 请求高手解答 如何生成 状态提示窗:如“正在刷新,请稍等....” HttpWebRequest访问http.a网址,但http.a转向到https.x,出现问题 C#中如何忽略错误 讲文件存入数据库中 this.table1TableAdapter.Adapter.SelectCommand.CommandText 如何赋值 问一个菜鸟级别的问题
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
//分析了一下网页的格式,
//下面
//提供一个思路,如果要查询几万条的话,速度肯定不行
//我这里每次调用大概需要2秒钟
//需要调用 WebClient.DownloadStringAsync 这个异步方法,
//在回调方法中进行处理
string careID = "320725197905231232"; //查询的号码 System.Net.WebClient client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.Default;
string reply = client.DownloadString( "http://www.sz800.com/sfz/index.asp?xian=" + careID );
string city = string.Empty; //原户籍地:
string birthday = string.Empty; //出生年月:
string sex = string.Empty; //性 别:
string msg = string.Empty; //提示: int iBegin = -1; //开始位置
int iEnd = -1; //结束位置 iBegin = reply.IndexOf( "查询号码:" );
if ( iBegin == -1 )
{
//没查到信息,
//可以在循环中继续查询下一个号码
return;
} reply = reply.Substring( iBegin ); //取从 查询号码:开始到最后的内容 //原户籍地
iBegin = reply.IndexOf( "原户籍地:" );
iEnd = reply.IndexOf( "<br></td></tr>", iBegin );
city = reply.Substring( iBegin, iEnd - iBegin ); //出生年月:
iBegin = reply.IndexOf( "出生年月:" );
iEnd = reply.IndexOf( "<br></td></tr>", iBegin );
birthday = reply.Substring( iBegin, iEnd - iBegin ); //性别:
iBegin = reply.IndexOf( "性 别:" );
iEnd = reply.IndexOf( "</td></tr>", iBegin );
sex = reply.Substring( iBegin, iEnd - iBegin ).Replace( " ", "" ); //提示信息
iBegin = reply.IndexOf( "提示:" );
iEnd = reply.IndexOf( "</td>", iBegin );
msg = reply.Substring( iBegin, iEnd - iBegin ); MessageBox.Show( string.Format( "查询号码:{0}\n{1}\n{2}\n{3}\n{4}", careID, city, birthday, sex, msg ) );
//下面
//提供一个思路,如果要查询几万条的话,速度肯定不行
//我这里每次调用大概需要2秒钟
//需要调用 WebClient.DownloadStringAsync 这个异步方法,
//在回调方法中进行处理
string careID = "320621197905231235"; //查询的号码 System.Net.WebClient client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.Default;
string reply = client.DownloadString( "http://www.sz800.com/sfz/index.asp?xian=" + careID );
string city = string.Empty; //原户籍地:
string birthday = string.Empty; //出生年月:
string sex = string.Empty; //性 别:
string msg = string.Empty; //提示: int iBegin = -1; //开始位置
int iEnd = -1; //结束位置 iBegin = reply.IndexOf( "查询号码:" );
if ( iBegin == -1 )
{
//没查到信息,
//可以在循环中继续查询下一个号码
return;
} reply = reply.Substring( iBegin ); //取从 查询号码:开始到最后的内容 //原户籍地
iBegin = reply.IndexOf( "原户籍地:" );
iEnd = reply.IndexOf( "<br></td></tr>", iBegin );
city = reply.Substring( iBegin, iEnd - iBegin ); //出生年月:
iBegin = reply.IndexOf( "出生年月:" );
iEnd = reply.IndexOf( "<br></td></tr>", iBegin );
birthday = reply.Substring( iBegin, iEnd - iBegin ); //性别:
iBegin = reply.IndexOf( "性 别:" );
iEnd = reply.IndexOf( "</td></tr>", iBegin );
sex = reply.Substring( iBegin, iEnd - iBegin ).Replace( " ", "" ); //提示信息,有两种,一种是提示,说明号码有问题的
//一种是“结果”,说明正确的
iBegin = reply.IndexOf( "提示:" );
if ( iBegin != -1 )
{
iEnd = reply.IndexOf( "</td>", iBegin );
msg = reply.Substring( iBegin, iEnd - iBegin );
}
else
{
iBegin = reply.IndexOf( "结果:" );
iEnd = reply.IndexOf( "</td>", iBegin );
msg = reply.Substring( iBegin, iEnd - iBegin );
}
MessageBox.Show( string.Format( "查询号码:{0}\n{1}\n{2}\n{3}\n{4}", careID, city, birthday, sex, msg ) );
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="37%" height="30" valign="middle" align=center>身份证号码:
<input name=xian size=18 type=text>
<input name=submit type=submit value="快速查询"></td>
</tr>
</table>
</form>如何你可以做这样一个含下面内容的框架:<form action="http://www.sz800.com/sfz/index.asp" name=form1 method=post>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="37%" height="30" valign="middle" align=center>身份证号码:
<input name=xian size=18 type=text>
<input name=submit type=submit value="快速查询"></td>
</tr>
</table>
</form>再做数据处理,应该可以的,你试试看。