1. 要在A页面,输入2个字段值,点查询
2. 点完查询后, 会跳转到另外一个页面显示查询结果, URL在跳转之后变到B页面A在点查询时候, 表单提交查询里面的代码
<form method="post" action="netcar/FindTwo.aspx" id="formthree">
"netcar/FindTwo.aspx" 是B页面的地址完整的网址是http://www.域名.com/netcar/FindTwo.aspx
但是如果赋值为完整网址,那么抓取B页面的文字,不是点了查询后的页面, 所以也就取不到我要的结果 string strurl = wb.Url.LocalPath.ToString(); //欲获取的网页地址 要 http://
WebClient myWebClient = new WebClient(); //创建WebClient实例myWebClient //获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。
myWebClient.Credentials = CredentialCache.DefaultCredentials; //从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
byte[] pagedata = myWebClient.DownloadData(@strurl);
string result = Encoding.Default.GetString(pagedata); //如果获取网站页面采用的是GB2312,则使用这句 请教如何解决这个跳转页面之后,取字段值的问题
2. 点完查询后, 会跳转到另外一个页面显示查询结果, URL在跳转之后变到B页面A在点查询时候, 表单提交查询里面的代码
<form method="post" action="netcar/FindTwo.aspx" id="formthree">
"netcar/FindTwo.aspx" 是B页面的地址完整的网址是http://www.域名.com/netcar/FindTwo.aspx
但是如果赋值为完整网址,那么抓取B页面的文字,不是点了查询后的页面, 所以也就取不到我要的结果 string strurl = wb.Url.LocalPath.ToString(); //欲获取的网页地址 要 http://
WebClient myWebClient = new WebClient(); //创建WebClient实例myWebClient //获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。
myWebClient.Credentials = CredentialCache.DefaultCredentials; //从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
byte[] pagedata = myWebClient.DownloadData(@strurl);
string result = Encoding.Default.GetString(pagedata); //如果获取网站页面采用的是GB2312,则使用这句 请教如何解决这个跳转页面之后,取字段值的问题
<form method="post" action="netcar/FindTwo.aspx" id="formthree">
<li class="lithree5"></li>
<li class="lithree1"></li>
<li class="lithree2" style="left: 40px; top: 10px"> 姓名:
<input name="txtName" type="text" id="txtDname" size="27" />
<br />
<br />
<select id="WZJFQueryType" name="QueryTypeLst">
<option value="1" selected>驾照档案号</option>
<option value="2">驾驶证号</option>
</select>
<input type="text" name="txtCertificate" id="txtCer" />
</li>
<li class="lithree3" onclick="checkthree()"><a href="#">查询</a></li>
<li class="lithree4">查询信息需同时输入姓名,驾照档案号或驾驶证号。</li>
</form>
表单HTML代码是这样的, 我提交后, 获得的网页内容还是没有提交表单之前的内容,不是查询后的也没内容
代码:
try
{
postData = "txtDname=宋世强&txtCer=510200723375"; HttpWebRequest requestScore = (HttpWebRequest)WebRequest.Create("http://www.cqjg.gov.cn/netcar/FindTwo.aspx"); ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
requestScore.Method = "Post";
requestScore.ContentType = "application/x-www-form-urlencoded";
requestScore.ContentLength = data.Length;
requestScore.KeepAlive = true; Stream stream = requestScore.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse responseSorce = (HttpWebResponse)requestScore.GetResponse();
StreamReader reader = new StreamReader(responseSorce.GetResponseStream(), Encoding.GetEncoding("gb2312"));
string content = reader.ReadToEnd(); requestScore = null;
responseSorce.Close();
responseSorce = null;
reader = null;
stream = null; }
catch (Exception ex)
{
//throw new Exception(e.Message);
}