各位好,小弟爬取yes123網站首頁,提交表單數據,如查詢地區、職務等,查看返回的Response,表單確實有填入POST提交的數據,但未取得相應的內容,例如提交地區設定基隆全區,返回卻出現其它縣市資料,職務亦同。
不知哪裡出錯,請各位高手幫忙,謝謝。
程式碼如下:
string url = "https://www.yes123.com.tw/wk_index/joblist.asp";
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36";
request.Host = "www.yes123.com.tw";
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string postParam =
"find_zone_mode1=1_1001_0001_000" +
"&" +
"s_find_zone_mode1=基隆全區" +
"&" +
"find_work_mode1=2_1001_0001_0000" +
"&" +
"s_find_work_mode1=行政/總務全部" +
"&" +
"order_ascend=desc" +
"&" +
"strrec=0" +
"&" +
"search_type=job" +
"&" +
"search_from=joblist";
Encoding encoding = Encoding.UTF8;
byte[] postData = encoding.GetBytes(postParam);
request.ContentLength = postData.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(postData, 0, postData.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var result = "";
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader streamReader = new StreamReader(responseStream, encoding))
{
result = streamReader.ReadToEnd();
Console.WriteLine(result);
}
}
你把POST PARAM改成這個試試看
string postParam = "find_zone_mode1=1_1001_0001_0000&s_find_zone_mode1=基隆全區&find_work_mode1=2_1001_0001_0000&s_find_work_mode1=行政/總務全部&order_ascend=desc&strrec=0&search_type=job&search_from=joblist";
結論:
你的find_zone_mode1=1_1001_0001_000 少了一個0
find_zone_mode1=1_1001_0001_0000