I am a novice in programming. I have a project where I have to get data from a website (I ll be posting the website below). But it happens that I first have to select a date and press a 'Go' button and then click on another Button/Link 'View in Excel' to download this data. I cannot find a way to first click the 'Go' button after selecting my required date and then click the second button 'View in Excel' through my c# code.
Any help will be appreciated.
PS: You can check the link for yourselves http://www.mcxindia.com/sitepages/BhavCopyDateWiseArchive.aspx
The above code gives me the file only for the last available date. I am not able to get it for the date I want.
Any help will be appreciated.
PS: You can check the link for yourselves http://www.mcxindia.com/sitepages/BhavCopyDateWiseArchive.aspx
private void Form1_Load(object sender, EventArgs e) { WebClient webClient = new WebClient(); byte[] b = webClient.DownloadData("http://www.mcxindia.com/sitepages/BhavCopyDatewise.aspx"); string s = System.Text.Encoding.UTF8.GetString(B)/>/>; var __EVENTVALIDATION = ExtractVariable(s, "__EVENTVALIDATION"); //__EVENTVALIDATION.Dump(); var forms = new NameValueCollection(); forms["__EVENTTARGET"] = "btnLink_Excel"; forms["__EVENTARGUMENT"] = ""; forms["__VIEWSTATE"] = ExtractVariable(s, "__VIEWSTATE"); forms["mTbdate"] = "01%2F15%2F2013"; forms["__EVENTVALIDATION"] = __EVENTVALIDATION; webClient.Headers.Set(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); var responseData = webClient.UploadValues(@"http://www.mcxindia.com/sitepages/BhavCopyDatewise.aspx", "POST", forms); System.IO.File.WriteAllBytes(@"c:\11152011.csv", responseData); } private static string ExtractVariable(string s, string valueName) { string tokenStart = valueName + "\" value=\""; string tokenEnd = "\" />"; int start = s.IndexOf(tokenStart) + tokenStart.Length; int length = s.IndexOf(tokenEnd, start) - start; return s.Substring(start, length); }
The above code gives me the file only for the last available date. I am not able to get it for the date I want.