|
http://house.shunde.net.cn/sellhouse.aspx
我想获取每页的数据,分页是用的post方法
当我把__EVENTTARGET,__EVENTARGUMENT,__VIEWSTATE 提交的时候 返回的信息还是第一页的
代码如下:
用了HtmlAgilityPack解析html了
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string sHtml = string.Empty;
public string getcontroldata(string controlid)
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(sHtml);
HtmlNode node = doc.DocumentNode.SelectSingleNode(string.Format("//*[@id=\"{0}\"]", controlid));
if (node != null && node.Attributes["value"] != null)
{
return node.Attributes["value"].Value;
}
return "";
}
private void button1_Click(object sender, EventArgs e)
{
int iPageNo = 1;
bool bExitFlag = false;
string sCurrentUrl = "http://house.shunde.net.cn/sellhouse.aspx";
do
{
if (iPageNo == 1)
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = sCurrentUrl,//URL 必需项
ICredentials = CredentialCache.DefaultCredentials,
};
HttpResult result = http.GetHtml(item);
sHtml = result.Html;
string cookie = result.Cookie;
}
else
{
string postdata =
"__EVENTTARGET=dgMain$ctl28$ctl01"
+ "&__EVENTARGUMENT="
+ "&__VIEWSTATE=" + getcontroldata("__VIEWSTATE");
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = sCurrentUrl,//URL 必需项
ICredentials = CredentialCache.DefaultCredentials,
Method = "POST",
Postdata = postdata,
Referer = "http://house.shunde.net.cn/sellhouse.aspx"
};
HttpResult result = http.GetHtml(item);
sHtml = result.Html;
string cookie = result.Cookie;
}
iPageNo++;
}
while (!bExitFlag);
}
}
|
|