我给你试了一下,发现还只能获取到第一页的数据,那个如何post不同的页码获取不同的数据,我还没找到方法,不过可以给你参考下 他的分页是用的ASPNETPager,我不知道如何构造不同的页码参数using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Net; using System.IO; using System.Text;public partial class Test_csdn_GetData : System.Web.UI.Page { public static string url = "http://www.sdyypt.net/dataservice/netmedicalinfo.aspx?hitproductid="; protected void Page_Load(object sender, EventArgs e) { GetRemoteData(); } private void GetRemoteData() { ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "ctl00$rightCon$ProductQuery$AspNetPager1_input=" + "51"; postData += ("&ctl00$rightCon$ProductQuery$AspNetPager1_input=" + "55");
byte[] data = encoding.GetBytes(postData); HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create(url); wr.Method = "POST"; wr.ContentType = "application/x-www-form-urlencoded"; wr.ContentLength = data.Length; Stream newStream = wr.GetRequestStream(); newStream.Write(data, 0, data.Length); newStream.Close(); using (WebResponse ws = wr.GetResponse()) { StreamReader sr = new StreamReader(ws.GetResponseStream(), Encoding.UTF8); string html = sr.ReadToEnd(); Response.Write(html); } } }
如果怕麻烦,找exl组件,一个dataset就能导出exl.何必呢.
public static void DataTable2Excel(System.Data.DataTable dtData)
10 {
11 System.Web.UI.WebControls.DataGrid dgExport = null;
12 // 当前对话
13 System.Web.HttpContext curContext = System.Web.HttpContext.Current;
14 // IO用于导出并返回excel文件
15 System.IO.StringWriter strWriter = null;
16 System.Web.UI.HtmlTextWriter htmlWriter = null;
17
18 if (dtData != null)
19 {
20 // 设置编码和附件格式
21 curContext.Response.ContentType = "application/vnd.ms-excel";
22 curContext.Response.ContentEncoding =System.Text.Encoding.UTF8;
23 curContext.Response.Charset = "";
24
25 // 导出excel文件
26 strWriter = new System.IO.StringWriter();
27 htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
28
29 // 为了解决dgData中可能进行了分页的情况,需要重新定义一个无分页的DataGrid
30 dgExport = new System.Web.UI.WebControls.DataGrid();
31 dgExport.DataSource = dtData.DefaultView;
32 dgExport.AllowPaging = false;
33 dgExport.DataBind();
34
35 // 返回客户端
36 dgExport.RenderControl(htmlWriter);
37 curContext.Response.Write(strWriter.ToString());
38 curContext.Response.End();
39 }
40 }
我给你试了一下,发现还只能获取到第一页的数据,那个如何post不同的页码获取不同的数据,我还没找到方法,不过可以给你参考下
他的分页是用的ASPNETPager,我不知道如何构造不同的页码参数using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;public partial class Test_csdn_GetData : System.Web.UI.Page
{
public static string url = "http://www.sdyypt.net/dataservice/netmedicalinfo.aspx?hitproductid=";
protected void Page_Load(object sender, EventArgs e)
{
GetRemoteData();
}
private void GetRemoteData()
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "ctl00$rightCon$ProductQuery$AspNetPager1_input=" + "51";
postData += ("&ctl00$rightCon$ProductQuery$AspNetPager1_input=" + "55");
byte[] data = encoding.GetBytes(postData); HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create(url);
wr.Method = "POST";
wr.ContentType = "application/x-www-form-urlencoded";
wr.ContentLength = data.Length;
Stream newStream = wr.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close(); using (WebResponse ws = wr.GetResponse())
{
StreamReader sr = new StreamReader(ws.GetResponseStream(), Encoding.UTF8);
string html = sr.ReadToEnd();
Response.Write(html); }
}
}
状态栏有JAVASCRIPT代码
不知道能否从此找到信息我看不懂你的代码,能帮忙分析下吗
1,遍历所有Document的元素,得到页码输入框和页导航按钮GO
2,循环给页码赋值
3,在webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)事件里获取table的值,并写入SQL,或其他处理方式我简单试了试,是可以的
参考代码private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement btn = null;
HtmlDocument doc = webBrowser1.Document;
for (int i = 0; i < doc.All.Count; i++)
{
if (doc.All[i].TagName.ToUpper().Equals("INPUT"))
{
switch (doc.All[i].Name)
{
case "ctl00$rightCon$ProductQuery$AspNetPager1_input": //页码框
doc.All[i].InnerText = "2"; //页码赋值
break;
case "ctl00$rightCon$ProductQuery$AspNetPager1": //GO按钮
btn = doc.All[i];
break;
}
}
}
btn.InvokeMember("Click");//点击GO按钮
}