使用WebClient C#从aspx页面进行WebScrapping

时间:2017-09-19 10:19:33

标签: c# asp.net web-scraping webclient viewstate

我试图从aspx页面抓取数据,该页面有三个下拉列表:State,District和City。它们被实现为服务器端回发的依赖性下拉列表。 我拥有州,区和城市的所有ID。我正在使用WebClient编写一个控制台应用程序,将所有三个下拉列表作为表单数据发布到页面。但每次重定向到错误页面。任何人都可以帮我一次性设置所有下拉值吗?

代码段:

var formValues = new NameValueCollection();
formValues["__VIEWSTATE"] = Extract("__VIEWSTATE", responseString);
formValues["__EVENTVALIDATION"] = Extract("__EVENTVALIDATION", responseString);
formValues["ddlSelectLanguage"] = "en-US";
formValues["ddlState"] = "19";
formValues["DDLDistrict"] = "237";
formValues["DDLVillage"] = "bcab59fd-35d2-e111-882d-001517f1d35c";
client.Headers.Set(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36");
var responseData = client.UploadValues(firstPage, formValues);
responseString = Encoding.ASCII.GetString(responseData);

0 个答案:

没有答案