简体   繁体   English

我如何从 aspx 网站 __doPostBack 表单中抓取数据?

[英]How do i scrape data from an aspx site, __doPostBack form?

I'm trying to crawl/scrape a website using c# console app, getting the initial page is not a problem, but I need to get pages when I click on the button who has the __doPostBack action.我正在尝试使用 c# 控制台应用程序抓取/抓取网站,获取初始页面不是问题,但是当我单击具有 __doPostBack 操作的按钮时,我需要获取页面。

I try with these settings but this already back results from the initial page:我尝试使用这些设置,但这已经从初始页面返回结果:

I Update my code我更新我的代码

            var client1 = new RestClient("https://example.com");
            var request1 = new RestRequest(Method.POST);
            IRestResponse initialResponse = client1.Execute(request1);


            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(initialResponse.Content);

            var formData = new Dictionary<string, string>();
            formData.Add("__EVENTTARGET", "ctl00$MainContentExample");
            formData.Add("__EVENTARGUMENT", "");
            formData.Add("ctl00$MainContent$CustomHiddenField", "");
            formData.Add("__VIEWSTATEGENERATOR", "B5682C7D");
            var divViewState = doc.DocumentNode
                .SelectSingleNode("//input[@name='__VIEWSTATE']").Attributes[3].Value;
            formData.Add("__VIEWSTATE", divViewState);
            var divEventValidation = doc.DocumentNode
                .SelectSingleNode("//input[@name='__EVENTVALIDATION']").Attributes[3].Value;
            formData.Add("__EVENTVALIDATION", divEventValidation);


            var client = new RestClient("https://example.com");
            var request = new RestRequest("/methodName",Method.POST);
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("Connection", "keep-alive");

            var c = "";
            var i = 0;
            foreach (var cookie in initialResponse.Cookies)
            {
                if(i==0)
                 c += cookie.Name + "=" + cookie.Value + "; ";
                else
                    c += cookie.Name + "=" + cookie.Value;

                i++;
            }
            request.AddHeader("Cookie", c);
           request.AddHeader("Accept-Encoding", "gzip, deflate, br");
            request.AddHeader("Host", "example.com");
            request.AddHeader("Cache-Control", "max-age=0");
            request.AddHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
            request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddHeader("Accept-Language", "en-US,en;q=0.9");
            request.AddHeader("Content-Encoding", "utf-8");

            var json = JsonConvert.SerializeObject(formData);
            byte[] byteData = Encoding.UTF8.GetBytes(json);

            request.AddHeader("Content-Length", byteData.Length.ToString())


            request.AddParameter("undefined", byteData, ParameterType.RequestBody);

            IRestResponse response2 = client.Execute(request);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据数据库中的项目列表将图像添加到aspx站点 - How do I add images to an aspx site based off of a list of items from a database 如何通过在浏览器中手动键入aspx文件名来防止访问Web表单? - How do I prevent a web form from being accessed by manually typing the aspx file name into the browser? 如何用来自不同相关表的多个下拉列表填充ASPX C#表单? - How do I populate an ASPX C# Form with multiple dropdowns from different related tables? 如何将数据从ASPX页面中的表单传递到MVC控制器? - How can I pass data from a form in an ASPX page to a MVC controller? 如何将Site.Master.cs中的字符串或值发送到Default.aspx.cs中的标签/文本框中的值/字符串? - How do I send a string or value from the Site.Master.cs to my Default.aspx.cs to the value/string in a label/textbox? 我如何在endrequest方法中的_dopostback()中传递参数? - How do i get the parameter passed in _dopostback() in endrequest method? 如何将XML数据从MS Access传递到C#中的Server .ASPX页面? - How do I pass XML data from MS Access to Server .ASPX Page in C#? 如何使用已经部署的常规html站点部署.aspx Webform页面? - How do I deploy .aspx webform pages with a regular html site that has already been deployed? 从ASPX Web表单读取JSON数据 - reading JSON data from aspx web form 如何防止服务器按钮刷新ASPX视图? - How do I keep a server button from refreshing an ASPX View?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM