我尝试使用webclient从网站中提取数据,但我不知道Post的确切参数,并且我收到了永久的空数据。
Website: Red Arrow is the action and on green its the data i want
要查看帖子参数,请使用Google Ghrome开发者工具,然后在标签" Network"我寻找Post Request Header。
我的C#编码:
旧代码 - 这不适用于webclient
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
using (WebClient wc = new WebClient())
{
wc.Headers.Add(HttpRequestHeader.Accept, "*/*");
wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,es;q=0.2");
wc.Headers.Add(HttpRequestHeader.CacheControl, "no-cache");
//wc.Headers.Add(HttpRequestHeader.Connection, "keep-alive");
//wc.Headers.Add(HttpRequestHeader.ContentLength, "18801");
wc.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded; charset=UTF-8");
wc.Headers.Add(HttpRequestHeader.Cookie, "_pk_id.70.0919=b6cdc4d1ee3456d0.1456252054.2.1456255268.1456255085.;" + "ASP.NET_SessionId=zlth2slu3o05ek511w5jb4rt");
wc.Headers.Add(HttpRequestHeader.Host, "www.citius.mj.pt");
wc.Headers.Add("Origin", "https://www.citius.mj.pt");
wc.Headers.Add(HttpRequestHeader.Referer, "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx");
wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36");
wc.Headers.Add("X-MicrosoftAjax", "Delta=true");
wc.Headers.Add("X-Requested-With", "XMLHttpRequest");
string parametro1 = "ctl00$ContentPlaceHolder1$ScriptManager1=ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch";
string parametro2 = "ctl00$ContentPlaceHolder1$rbtlTribunais=False";
string parametro3 = "ctl00$ContentPlaceHolder1$ddlTribunais=- Todos os Tribunais -";
string parametro4 = "ctl00$ContentPlaceHolder1$rblDias=todos";
string parametro5 = "__EVENTTARGET=";
string parametro6 = "__EVENTARGUMENT=";
string parametro7 = "__LASTFOCUS=";
string parametro8 = "__VIEWSTATE=/wEPDwULLTE2MDIzOTkyMDcPFg4eCFBhZ2VTaXplAgoeCFdyaXRlTG9naB4OU2VhcmNoQ3JpdGVyaWEyvwMAAQAAAP////8BAAAAAAAAAAwCAAAAS1RyaWJ1bmFpc05ldC5XZWJzaXRlLCBWZXJzaW9uPTIuNC4zLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAUBAAAAPVRyaWJ1bmFpc05ldC5XZWJzaXRlLkRBTC5TZXJ2aWNlcy5WZW5kYUFudW5jaW9zU2VhcmNoQ3JpdGVyaWEDAAAAC19pZFVuT3JnUmVmBV9kaWFzCV9leHRpbnRvcwMDA25TeXN0ZW0uTnVsbGFibGVgMVtbU3lzdGVtLkludDMyLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXW5TeXN0ZW0uTnVsbGFibGVgMVtbU3lzdGVtLkludDMyLCBtc2NvcmxpYiwgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODldXQ5TeXN0ZW0uQm9vbGVhbgIAAAAKCggBAAseC1JlY29yZENvdW50AscJHgpQYWdlTnVtYmVyAgEeC0xhc3RMb3dlcklkZB4LTGFzdFVwcGVySWRkFgJmD2QWAgIDD2QWAgIFD2QWBAIBD2QWAmYPZBYEAgEPEGRkFgFmZAIDDxAPFggeFEFwcGVuZERhdGFCb3VuZEl0ZW1zZx4NRGF0YVRleHRGaWVsZAUETm9tZR4ORGF0YVZhbHVlRmllbGQFCklkVW5PcmdSZWYeC18hRGF0YUJvdW5kZ2QQFb0BFi0gVG9kb3Mgb3MgV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gECm9yEzwgC5rel0AYCypDajw8CqZjBjgoCypCqjw8C0evQkAUC5re10AYCotnY0QgCvMX6pQMCypCyjw8C5re90AYCqJjFjgoCotmg0QgCx8+mzAIC2Y7L5QwCvtnI0QgC8ret0AYC3o7P5QwCpJj5jgoC2Y7f5QwC/bep0AYCl9ygzwgCl9yczwgCudnc0QgCwZD+jw8C/bfJ0AYCp5j5jgoCrOrYkAUCwZD6jw8CwZCyjw8Ci8XmpQMCq+rw0AUCtsWe+gMCtsWS+gMCq+r80AUC+LelkAcCx47HpQ0CopjpzgoCndyAjwkCzJDWzw8CpNnIkQkC2c+mjAMC+onE4wcCheWA7g0CgsPTmQYC8YbIZALotaH2CgLkiaziCQKIwtyjBwKPvOOHBwKn2efXAgKh2ru0BwLkiYifDwKCg+qACwLZ6ZORCAL/wfXjBwL9wcnjBwK5oIOQDALwrqOOCwL3uvOGAtOIyfznMNQ0NVck838xcE7itysvOowRqyKO3jGrE24T";
string parametro10 = "__ASYNCPOST=true";
string parametro11 = "ctl00$ContentPlaceHolder1$btnSearch=Pesquisar";
string parametros = parametro1 + "&" + parametro2 + "&" + parametro3 + "&" + parametro4 + "&" + parametro5 + "&" + parametro6 + "&" + parametro7 + "&" + parametro8 + "&" + parametro9 + "&" + parametro10 + "&" + parametro11;
string HtmlResult = wc.UploadString(URI, parametros);
}
我做错了什么?
来自SAKURA + MYCODE的工作代码跳转到下一页
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
CookieContainer cc = new CookieContainer();
HttpWebRequest h = (HttpWebRequest)WebRequest.Create(URI);
h.CookieContainer = cc;
HttpWebResponse hr = (HttpWebResponse)h.GetResponse();
using (var s = hr.GetResponseStream())
{
using (var r = new StreamReader(s, Encoding.UTF8))
{
string html = r.ReadToEnd();
Match mVS = Regex.Match(html, "id=\"__VIEWSTATE\" value=\"(.*?)\"", RegexOptions.Singleline);
Match mEV = Regex.Match(html, "id=\"__EVENTVALIDATION\" value=\"(.*?)\"", RegexOptions.Singleline);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
//param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$upResultados|ctl00$ContentPlaceHolder1$Pager1$btnNextPage");
param.Add("__EVENTTARGET", "");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
param.Add("__VIEWSTATE", mVS.Groups[1].Value);
param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__ASYNCPOST", "true");
param.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post = "";
foreach (var i in param)
{
post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
var data = Encoding.UTF8.GetBytes(post);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
int x = 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Dictionary<string, string> param2 = new Dictionary<string, string>();
//param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
param2.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$upResultados|ctl00$ContentPlaceHolder1$Pager1$btnNextPage");
param2.Add("__EVENTTARGET", "");
param2.Add("__EVENTARGUMENT", "");
param2.Add("__LASTFOCUS", "");
param2.Add("__VIEWSTATE", mVS.Groups[1].Value);
param2.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param2.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param2.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param2.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param2.Add("__ASYNCPOST", "true");
//param2.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post2 = "";
foreach (var i in param2)
{
post2 += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
}
var data2 = Encoding.UTF8.GetBytes(post2);
HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(URI);
request2.CookieContainer = cc;
request2.Referer = URI;
request2.Method = "POST";
request2.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request2.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request2.Headers.Add("Origin", "https://www.citius.mj.pt");
request2.Headers.Add("X-Requested-With", "XMLHttpRequest");
request2.Headers.Add("X-MicrosoftAjax: Delta=true");
request2.ContentLength = data2.Length;
using (var stream2 = request2.GetRequestStream())
{
stream2.Write(data2, 0, data2.Length);
}
HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd();
int y = 2;
}
}
答案 0 :(得分:1)
问题是您在发送回服务器时没有对POST数据进行编码。您可以使用WebUtility.UrlEncode
对其进行封尾。
以下是对您的代码的修改:
注意:在using
中包装第二个请求函数,就像我为您做的第一个请求一样:
string URI = "https://www.citius.mj.pt/Portal/consultas/ConsultaVendaAnuncios.aspx";
CookieContainer cc = new CookieContainer();
HttpWebRequest h = (HttpWebRequest)WebRequest.Create(URI);
h.CookieContainer = cc;
HttpWebResponse hr = (HttpWebResponse)h.GetResponse();
using (var s = hr.GetResponseStream())
{
using (var r = new StreamReader(s, Encoding.UTF8))
{
string html = r.ReadToEnd();
//Console.WriteLine(html);
Match mVS = Regex.Match(html, "id=\"__VIEWSTATE\" value=\"(.*?)\"", RegexOptions.Singleline);
//Console.WriteLine(mVS.Groups[1].Value);
Match mEV = Regex.Match(html, "id=\"__EVENTVALIDATION\" value=\"(.*?)\"", RegexOptions.Singleline);
Dictionary<string, string> param = new Dictionary<string, string>();
param.Add("ctl00$ContentPlaceHolder1$ScriptManager1", "ctl00$ContentPlaceHolder1$ScriptManager1|ctl00$ContentPlaceHolder1$btnSearch");
param.Add("__EVENTTARGET", "");
param.Add("__EVENTARGUMENT", "");
param.Add("__LASTFOCUS", "");
param.Add("__VIEWSTATE", mVS.Groups[1].Value);
param.Add("__EVENTVALIDATION", mEV.Groups[1].Value);
param.Add("ctl00$ContentPlaceHolder1$rbtlTribunais", "False");
param.Add("ctl00$ContentPlaceHolder1$ddlTribunais", "- Todos os Tribunais -");
param.Add("ctl00$ContentPlaceHolder1$rblDias", "todos");
param.Add("__ASYNCPOST", "true");
param.Add("ctl00$ContentPlaceHolder1$btnSearch", "Pesquisar");
string post = "";
foreach (var i in param) post += WebUtility.UrlEncode(i.Key) + "=" + WebUtility.UrlEncode(i.Value) + "&";
var data = Encoding.UTF8.GetBytes(post);
Console.WriteLine(data.Length);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
request.CookieContainer = cc;
request.Referer = URI;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36";
request.Headers.Add("Origin", "https://www.citius.mj.pt");
request.Headers.Add("X-Requested-With", "XMLHttpRequest");
request.Headers.Add("X-MicrosoftAjax: Delta=true");
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine(responseString);
}
}